From 3ffeaf1f5dbf3e225dc536066d0fedda3f38ac70 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 15 May 2018 20:32:22 -0700 Subject: Removed "for all"-style iteration and changed "for % from 1 to 10"-style to "for % in 1 to 10" for consistency. --- core/collections.nom | 34 ++++++++-------------------------- core/control_flow.nom | 13 +++---------- core/math.nom | 12 ++++++++---- 3 files changed, 19 insertions(+), 40 deletions(-) (limited to 'core') diff --git a/core/collections.nom b/core/collections.nom index 189aa5d..7922a4f 100644 --- a/core/collections.nom +++ b/core/collections.nom @@ -66,33 +66,18 @@ immediately %comprehension.%i <- %expression return %comprehension - parse [%expression for all %iterable] as - %expression for % in %iterable - parse [..] - %expression for %index from %start to %stop via %step - %expression for %index from %start to %stop by %step + %expression for %index in %start to %stop via %step + %expression for %index in %start to %stop by %step ..as result of %comprehension <- [] - for %index from %start to %stop via %step + for %index in %start to %stop via %step add %expression to %comprehension return %comprehension - parse [%expression for all %iterable] as - %expression for % in %iterable - - parse [%expression for %var from %start to %stop] as - %expression for %var from %start to %stop via 1 - - parse [..] - %expression for all %start to %stop by %step - %expression for all %start to %stop via %step - ..as - %expression for % from %start to %stop via %step - - parse [%expression for all %start to %stop] as - %expression for all %start to %stop via 1 + parse [%expression for %var in %start to %stop] as + %expression for %var in %start to %stop via 1 parse [%expression for %key = %value in %iterable] as result of @@ -109,9 +94,6 @@ immediately %comprehension.%key <- %value return %comprehension - parse [%key = %value for all %iterable] as - %key = %value for % in %iterable - parse [%key = %value for %src_key = %src_value in %iterable] as result of %comprehension <- {} @@ -142,18 +124,18 @@ immediately immediately action [%items sorted, sorted %items] - %copy <- (% for all %items) + %copy <- (% for % in %items) sort %copy return %copy action [%items sorted by %key] - %copy <- (% for all %items) + %copy <- (% for % in %items) sort %copy by %key return %copy action [unique %items] %unique <- [] %seen <- {} - for all %items + for % in %items unless: % in %seen add % to %unique (% in %seen) <- (yes) diff --git a/core/control_flow.nom b/core/control_flow.nom index 3f20e10..8e7306d 100644 --- a/core/control_flow.nom +++ b/core/control_flow.nom @@ -140,8 +140,8 @@ immediately # Numeric range for loops immediately compile [..] - for %var from %start to %stop by %step %body - for %var from %start to %stop via %step %body + for %var in %start to %stop by %step %body + for %var in %start to %stop via %step %body ..to # This uses Lua's approach of only allowing loop-scoped variables in a loop assume (%var.type is "Var") or barf "Loop expected variable, not: \(%var's source code)" @@ -173,12 +173,7 @@ immediately return %lua immediately - parse [for %var from %start to %stop %body] as: for %var from %start to %stop via 1 %body - parse [..] - for all %start to %stop by %step %body - for all %start to %stop via %step %body - ..as: for % from %start to %stop via %step %body - parse [for all %start to %stop %body] as: for all %start to %stop via 1 %body + parse [for %var in %start to %stop %body] as: for %var in %start to %stop via 1 %body # For-each loop (lua's "ipairs()") immediately @@ -210,8 +205,6 @@ immediately end -- end of scope for stopping for-loop return %lua - parse [for all %iterable %body] as: for % in %iterable %body - # Dict iteration (lua's "pairs()") immediately compile [for %key = %value in %iterable %body] to diff --git a/core/math.nom b/core/math.nom index e79c8c3..c507b87 100644 --- a/core/math.nom +++ b/core/math.nom @@ -42,27 +42,31 @@ compile [all of %items, all %items] to unless: (%items' "type") is "List" return: Lua value "utils.all(\(%items as lua expr))" %clauses <- [] - for all (%items' "value"): lua> "table.insert(\%clauses, \(% as lua expr));" + for % in (%items' "value") + lua> "table.insert(\%clauses, \(% as lua expr));" return: Lua value "(\(%clauses joined with " and "))" parse [not all of %items, not all %items] as: not (all of %items) compile [any of %items, any %items] to unless: (%items' "type") is "List" return: Lua value "utils.any(\(%items as lua expr))" %clauses <- [] - for all (%items' "value"): lua> "table.insert(\%clauses, \(% as lua expr));" + for % in (%items' "value") + lua> "table.insert(\%clauses, \(% as lua expr));" return: Lua value "(\(%clauses joined with " or "))" parse [none of %items, none %items] as: not (any of %items) compile [sum of %items, sum %items] to unless: (%items' "type") is "List" return: Lua value "utils.sum(\(%items as lua expr))" %clauses <- [] - for all (%items' "value"): lua> "table.insert(\%clauses, \(% as lua expr));" + for % in (%items' "value") + lua> "table.insert(\%clauses, \(% as lua expr));" return: Lua value "(\(%clauses joined with " + "))" compile [product of %items, product %items] to unless: (%items' "type") is "List" return: Lua value "utils.product(\(%items as lua expr))" %clauses <- [] - for all (%items' "value"): lua> "table.insert(\%clauses, \(% as lua expr));" + for % in (%items' "value") + lua> "table.insert(\%clauses, \(% as lua expr));" return: Lua value "(\(%clauses joined with " * "))" action [avg of %items, average of %items] =lua "(utils.sum(\%items)/#\%items)" -- cgit v1.2.3