aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/math/infix.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/library/lux/math/infix.lux64
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))))