Fix do notation expressions without bindings

This commit is contained in:
Correl Roush 2014-04-24 09:47:12 -04:00
parent 615d427fa8
commit ecd20c50ec
2 changed files with 8 additions and 9 deletions

View file

@ -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)))
)

View file

@ -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)))))
(deftest do-nobindings
(is-equal #(just 3)
(do #(just 5)
#(just 3))))