diff options
author | Eduardo Julian | 2021-08-11 02:38:59 -0400 |
---|---|---|
committer | Eduardo Julian | 2021-08-11 02:38:59 -0400 |
commit | a62ce3f9c2b605e0033f4772b0f64c4525de4d86 (patch) | |
tree | ecbabe8f110d82b2e6481cf7c0532d4bd4386570 /stdlib/source/library/lux/math/infix.lux | |
parent | 464b6e8f5e6c62f58fa8c7ff61ab2ad215e98bd1 (diff) |
Relocated maybe and lazy from data to control.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/library/lux/math/infix.lux | 64 |
1 files changed, 34 insertions, 30 deletions
diff --git a/stdlib/source/library/lux/math/infix.lux b/stdlib/source/library/lux/math/infix.lux index 55653989a..a04cf8944 100644 --- a/stdlib/source/library/lux/math/infix.lux +++ b/stdlib/source/library/lux/math/infix.lux @@ -25,28 +25,32 @@ (#Unary Code Infix) (#Binary Infix Code Infix)) -(def: infix^ +(def: literal + (Parser Code) + ($_ <>.either + (<>\map code.bit <code>.bit) + (<>\map code.nat <code>.nat) + (<>\map code.int <code>.int) + (<>\map code.rev <code>.rev) + (<>\map code.frac <code>.frac) + (<>\map code.text <code>.text) + (<>\map code.identifier <code>.identifier) + (<>\map code.tag <code>.tag))) + +(def: expression (Parser Infix) - (<| <>.rec (function (_ infix^)) + (<| <>.rec (function (_ expression)) ($_ <>.or - ($_ <>.either - (<>\map code.bit <code>.bit) - (<>\map code.nat <code>.nat) - (<>\map code.int <code>.int) - (<>\map code.rev <code>.rev) - (<>\map code.frac <code>.frac) - (<>\map code.text <code>.text) - (<>\map code.identifier <code>.identifier) - (<>\map code.tag <code>.tag)) + ..literal (<code>.form (<>.many <code>.any)) - (<code>.tuple (<>.and <code>.any infix^)) + (<code>.tuple (<>.and <code>.any expression)) (<code>.tuple ($_ <>.either (do <>.monad [_ (<code>.this! (' #and)) - init_subject infix^ + init_subject expression init_op <code>.any - init_param infix^ - steps (<>.some (<>.and <code>.any infix^))] + init_param expression + steps (<>.some (<>.and <code>.any expression))] (in (product.right (list\fold (function (_ [op param] [subject [_subject _op _param]]) [param [(#Binary _subject _op _param) (` and) @@ -54,10 +58,10 @@ [init_param [init_subject init_op init_param]] steps)))) (do <>.monad - [init_subject infix^ + [init_subject expression init_op <code>.any - init_param infix^ - steps (<>.some (<>.and <code>.any infix^))] + init_param expression + steps (<>.some (<>.and <code>.any expression))] (in (list\fold (function (_ [op param] [_subject _op _param]) [(#Binary _subject _op _param) op param]) [init_subject init_op init_param] @@ -80,17 +84,17 @@ (#Binary left op right) (` ((~ op) (~ (prefix right)) (~ (prefix left)))))) -(syntax: .public (infix {expr infix^}) - {#.doc (doc "Infix math syntax." - (infix [x i.* +10]) - (infix [[x i.+ y] i.* [x i.- y]]) - (infix [sin [x i.+ y]]) - (infix [[x n.< y] and [y n.< z]]) - (infix [#and x n.< y n.< z]) - (infix [(n.* 3 9) gcd 450]) +(syntax: .public (infix {expr ..expression}) + {#.doc (example "Infix math syntax." + (infix [x i.* +10]) + (infix [[x i.+ y] i.* [x i.- y]]) + (infix [sin [x i.+ y]]) + (infix [[x n.< y] and [y n.< z]]) + (infix [#and x n.< y n.< z]) + (infix [(n.* 3 9) gcd 450]) - "The rules for infix syntax are simple." - "If you want your binary function to work well with it." - "Then take the argument to the right (y) as your first argument," - "and take the argument to the left (x) as your second argument.")} + "The rules for infix syntax are simple." + "If you want your binary function to work well with it." + "Then take the argument to the right (y) as your first argument," + "and take the argument to the left (x) as your second argument.")} (in (list (..prefix expr)))) |