diff --git a/src/maybe.lfe b/src/maybe.lfe index fecdc0d..c552732 100644 --- a/src/maybe.lfe +++ b/src/maybe.lfe @@ -16,16 +16,10 @@ (defun return (x) (tuple 'just x)) (defun fail (_) 'nothing) -;; (defmacro do statements -;; `(lists:foldl >>= (car statements) (cdr statements))) - - ;; (defmacro do statements - ;; `'(list ,@statements)) - (defun do-statement (((cons h '())) h) (((cons (list f '<- m) t)) (list ': 'maybe '>>= m (list 'lambda (list f) (do-statement t)))) - (((cons h t)) (list 'lambda '(_) (do-statement t))) + (((cons h t)) (list ': 'maybe '>> h (do-statement t))) ) diff --git a/test/unit/unit-maybe-tests.lfe b/test/unit/unit-maybe-tests.lfe index 29cd57b..dfe4724 100644 --- a/test/unit/unit-maybe-tests.lfe +++ b/test/unit/unit-maybe-tests.lfe @@ -37,8 +37,13 @@ (is-equal #(just 3) (maybe:>> #(just 5) #(just 3)))) -(deftest do +(deftest do-bindings (is-equal #(just 3) (do (a <- #(just 1)) (b <- #(just 2)) - (maybe:return (+ a b))))) \ No newline at end of file + (maybe:return (+ a b))))) + +(deftest do-nobindings + (is-equal #(just 3) + (do #(just 5) + #(just 3)))) \ No newline at end of file