diff options
Diffstat (limited to 'source/lux/control/comonad.lux')
-rw-r--r-- | source/lux/control/comonad.lux | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/source/lux/control/comonad.lux b/source/lux/control/comonad.lux index 7ea3b58a9..2543f34da 100644 --- a/source/lux/control/comonad.lux +++ b/source/lux/control/comonad.lux @@ -28,22 +28,25 @@ ## [Syntax] (defmacro #export (be tokens state) (case tokens - (\ (@list comonad [_ (#;TupleS bindings)] body)) - (let [body' (foldL (: (-> AST (, AST AST) AST) + (#;Cons comonad (#;Cons [_ (#;TupleS bindings)] (#;Cons body #;Nil))) + (let [g!map (: AST [["" -1 -1] (#;SymbolS ["" " map "])]) + g!split (: AST [["" -1 -1] (#;SymbolS ["" " split "])]) + body' (foldL (: (-> AST (, AST AST) AST) (lambda [body' binding] (let [[var value] binding] (case var [_ (#;TagS ["" "let"])] - (` (;let (~ value) (~ body'))) + (` (let (~ value) (~ body'))) _ - (` (extend (;lambda [(~ var)] (~ body')) - (~ value))))))) + (` (|> (~ value) (~ g!split) ((~ g!map) (lambda [(~ var)] (~ body'))))) + )))) body (reverse (as-pairs bindings)))] - (#;Right [state (@list (` (;case (~ comonad) - {#;return ;return #;bind ;bind} - (~ body'))))])) + (#;Right [state (#;Cons (` (case (~ comonad) + {#_functor {#F;map (~ g!map)} #unwrap (~ (' unwrap)) #split (~ g!split)} + (~ body'))) + #;Nil)])) _ (#;Left "Wrong syntax for be"))) |