mirror of
https://github.com/correl/calrissian.git
synced 2024-11-23 19:19:57 +00:00
Fix do notation expressions without bindings
This commit is contained in:
parent
615d427fa8
commit
ecd20c50ec
2 changed files with 8 additions and 9 deletions
|
@ -16,16 +16,10 @@
|
||||||
(defun return (x) (tuple 'just x))
|
(defun return (x) (tuple 'just x))
|
||||||
(defun fail (_) 'nothing)
|
(defun fail (_) 'nothing)
|
||||||
|
|
||||||
;; (defmacro do statements
|
|
||||||
;; `(lists:foldl >>= (car statements) (cdr statements)))
|
|
||||||
|
|
||||||
;; (defmacro do statements
|
|
||||||
;; `'(list ,@statements))
|
|
||||||
|
|
||||||
(defun do-statement
|
(defun do-statement
|
||||||
(((cons h '())) h)
|
(((cons h '())) h)
|
||||||
(((cons (list f '<- m) t)) (list ': 'maybe '>>=
|
(((cons (list f '<- m) t)) (list ': 'maybe '>>=
|
||||||
m
|
m
|
||||||
(list 'lambda (list f) (do-statement t))))
|
(list 'lambda (list f) (do-statement t))))
|
||||||
(((cons h t)) (list 'lambda '(_) (do-statement t)))
|
(((cons h t)) (list ': 'maybe '>> h (do-statement t)))
|
||||||
)
|
)
|
||||||
|
|
|
@ -37,8 +37,13 @@
|
||||||
(is-equal #(just 3)
|
(is-equal #(just 3)
|
||||||
(maybe:>> #(just 5) #(just 3))))
|
(maybe:>> #(just 5) #(just 3))))
|
||||||
|
|
||||||
(deftest do
|
(deftest do-bindings
|
||||||
(is-equal #(just 3)
|
(is-equal #(just 3)
|
||||||
(do (a <- #(just 1))
|
(do (a <- #(just 1))
|
||||||
(b <- #(just 2))
|
(b <- #(just 2))
|
||||||
(maybe:return (+ a b)))))
|
(maybe:return (+ a b)))))
|
||||||
|
|
||||||
|
(deftest do-nobindings
|
||||||
|
(is-equal #(just 3)
|
||||||
|
(do #(just 5)
|
||||||
|
#(just 3))))
|
Loading…
Reference in a new issue