aboutsummaryrefslogtreecommitdiff
path: root/core/math.nom
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-05-27 18:28:23 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-05-27 18:29:23 -0700
commit2e15c0fd5067318601e2f3b70ee6fc16ef58200d (patch)
tree0006e0825b2680d457bb531c3d079661b16d6bc8 /core/math.nom
parent6ce32bdd25694d71dc232c50a008f8824f8a75ce (diff)
Some tweaks/cleanup on the nomsu code as well as adding variable
mangling to 'parse % as %' to make almost hygienic macros.
Diffstat (limited to 'core/math.nom')
-rw-r--r--core/math.nom26
1 files changed, 16 insertions, 10 deletions
diff --git a/core/math.nom b/core/math.nom
index ed2cdb6..677230b 100644
--- a/core/math.nom
+++ b/core/math.nom
@@ -74,16 +74,22 @@ compile [min of %items, smallest of %items, lowest of %items] to
Lua value "utils.min(\(%items as lua expr))"
compile [max of %items, biggest of %items, largest of %items, highest of %items] to
Lua value "utils.max(\(%items as lua expr))"
-compile [min of %items by %value_expr] to
- Lua value ".."
- utils.min(\(%items as lua expr), function(_)
- return \(%value_expr as lua expr)
- end)
-compile [max of %items by %value_expr] to
- Lua value ".."
- utils.max(\(%items as lua expr), function(_)
- return \(%value_expr as lua expr)
- end)
+parse [min of %items by %item = %value_expr] as
+ result of
+ <- {%best:nil, %best_key:nil}
+ for %item in %items
+ %key <- %value_expr
+ if: (%best = (nil)) or (%key < %best_key)
+ <- {%best:%item, %best_key:%key}
+ return %best
+parse [max of %items by %item = %value_expr] as
+ result of
+ <- {%best:nil, %best_key:nil}
+ for %item in %items
+ %key <- %value_expr
+ if: (%best = (nil)) or (%key > %best_key)
+ <- {%best:%item, %best_key:%key}
+ return %best
# Random functions
action [seed random with %]