From ecd20c50ec91f00e8faee15a52180895c222bade Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Thu, 24 Apr 2014 09:47:12 -0400 Subject: [PATCH] Fix do notation expressions without bindings --- src/maybe.lfe | 8 +------- test/unit/unit-maybe-tests.lfe | 9 +++++++-- 2 files changed, 8 insertions(+), 9 deletions(-) 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