Updated formatting to use data forms.

This commit is contained in:
Duncan McGreggor 2015-05-21 18:20:06 -05:00
parent 25fbba197e
commit 1c9fe229cb
7 changed files with 44 additions and 44 deletions

View file

@ -5,9 +5,9 @@
(fail 1)))
(defun >>=
(((tuple 'error reason) f)
(tuple 'error reason))
(((tuple 'ok value) f)
((`#(error ,reason) f)
`#(error ,reason))
((`#(ok ,value) f)
(funcall f value))
(('ok f)
(funcall f 'ok)))
@ -16,7 +16,7 @@
(('ok)
'ok)
((x)
(tuple 'ok x)))
`#(ok ,x)))
(defun fail (reason)
(tuple 'error reason))
`#(error ,reason))

View file

@ -10,4 +10,4 @@
(defun return (x) x)
(defun fail (x)
(throw (tuple 'error x)))
(throw `#(error ,x)))

View file

@ -7,11 +7,11 @@
(defun >>=
(('nothing f)
'nothing)
(((tuple 'just x) f)
((`#(just ,x) f)
(funcall f x)))
(defun return (x)
(tuple 'just x))
`#(just ,x))
(defun fail (_)
'nothing)

View file

@ -3,17 +3,17 @@
(do-transform 2)))
(defun behaviour_info
(('callbacks) (list #(>>= 2)
(('callbacks) '(#(>>= 2)
#(return 1)
#(fail 1)))
((_) 'undefined))
(defun do-transform
((monad (cons h '()))
((monad `(,h . ()))
h)
((monad (cons (list f '<- m) t))
(list '>>= monad
m
(list 'lambda (list f) (do-transform monad t))))
((monad (cons h t))
(list '>> monad h (do-transform monad t))))
((monad `((,f <- ,m) . ,t))
`(>>= ,monad
,m
(lambda (,f) ,(do-transform monad t))))
((monad `(,h . ,t))
`(>> ,monad ,h ,(do-transform monad t))))

View file

@ -4,57 +4,57 @@
(include-lib "include/monads.lfe")
(defun new (inner-monad)
(tuple 'calrissian-state-transformer inner-monad))
`#(calrissian-state-transformer ,inner-monad))
(defun return
((x (tuple 'calrissian-state-transformer inner-monad))
((x `#(calrissian-state-transformer ,inner-monad))
(lambda (s) (call inner-monad 'return (tuple x s)))))
(defun fail
((reason (tuple 'calrissian-state-transformer inner-monad))
((reason `#(calrissian-state-transformer ,inner-monad))
(lambda (_) (call inner-monad 'fail reason))))
(defun >>=
((x f (tuple 'calrissian-state-transformer inner-monad))
((x f `#(calrissian-state-transformer ,inner-monad))
(lambda (s)
(call inner-monad '>>=
(funcall x s)
(match-lambda (((tuple x1 s1)) (funcall (funcall f x1) s1)))))))
(match-lambda ((`#(,x1 ,s1)) (funcall (funcall f x1) s1)))))))
(defun get (_)
(lambda (s)
(tuple s s)))
`#(,s ,s)))
(defun put (s _)
(lambda (_)
(tuple 'ok s)))
`#(ok ,s)))
(defun modify
((f (tuple 'calrissian-state-transformer inner-monad))
((f `#(calrissian-state-transformer ,inner-monad))
(lambda (s)
(tuple 'ok (call inner-monad 'return (funcall f s))))))
`#(ok ,(call inner-monad 'return (funcall f s))))))
(defun modify-and-return
((f (tuple 'calrissian-state-transformer inner-monad))
((f `#(calrissian-state-transformer ,inner-monad))
(lambda (s)
(let ((newstate (call inner-monad 'return (funcall f s))))
(tuple newstate newstate)))))
`#(,newstate ,newstate)))))
(defun eval
((m s (tuple 'calrissian-state-transformer inner-monad))
((m s `#(calrissian-state-transformer ,inner-monad))
(call inner-monad '>>=
(funcall m s)
(match-lambda (((tuple x s1))
(match-lambda ((`#(,x ,s1))
(call inner-monad 'return x))))))
(defun exec
((m s (tuple 'calrissian-state-transformer inner-monad))
((m s `#(calrissian-state-transformer ,inner-monad))
(call inner-monad '>>=
(funcall m s)
(match-lambda (((tuple x s1))
(match-lambda ((`#(,x ,s1))
(call inner-monad 'return s1))))))
(defun run
((m s (tuple 'calrissian-state-transformer inner-monad))
((m s `#(calrissian-state-transformer ,inner-monad))
(funcall m s)))

View file

@ -2,7 +2,7 @@
(export (behaviour_info 1)))
(defun behaviour_info
(('callbacks) (list #(run 2)
(('callbacks) `(#(run 2)
#(get 0)
#(put 1)
#(modify 1)

View file

@ -14,15 +14,15 @@
`(#(calrissian ,(get-version)))))
(defun module-info
(((tuple module _args))
((`#(,module ,_args))
;; Report exported function arities as (arity - 1) to account for
;; the extra argument supplied to tuple modules
(let ((fix-info (lambda (info-plist)
(let* ((exports (proplists:get_value 'exports info-plist))
(fix-arity (match-lambda
;; module_info is added by the compiler and therefore remains as-is
(((tuple 'module_info arity)) (tuple 'module_info arity))
(((tuple fun arity)) (tuple fun (- arity 1)))))
((`#(module_info ,arity)) `#(module_info ,arity))
((`#(,fun ,arity)) `#(,fun ,(- arity 1)))))
(info-dict (dict:from_list info-plist))
(new-dict (dict:store 'exports (lists:map fix-arity exports) info-dict))
(new-plist (dict:to_list new-dict)))