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. --- examples/how_do_i.nom | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'examples') diff --git a/examples/how_do_i.nom b/examples/how_do_i.nom index 1d8c523..3abaf46 100644 --- a/examples/how_do_i.nom +++ b/examples/how_do_i.nom @@ -38,6 +38,7 @@ say "Hello world!" Strings can contain a backslash followed by a variable, list, dict, or parenthesized expression. This escaped value will be converted to a readable string, like so: The value of %x is \%x, isn't that nice? + These are some numbers: \[1+1,2+1,3+1] The sum of 2 and 4 is \(2 + 4). If you need to use a plain ol' backslash, you can do \\ <-- that %format_str2 <- "Single-line strings can contain escape sequences like \", \\, \n, \065, and \x0A" @@ -109,20 +110,15 @@ when 3 = ? %list <- [1,2,3] for %x in %list say "For %x loop #\%x" -# There's also a slightly more concise version that automatically populates a loop variable "%" -for all %list - say "For all loop #\%" # How do I loop over a number range? # This is inclusive, so it will loop over 1,2, and 3 -for %i from 1 to 3 - say "For %i from 1 to 3 loop #\%i" -for all 1 to 3 - say "For all 1 to 3 loop #\%" +for %i in 1 to 3 + say "For %i in 1 to 3 loop #\%i" # This will print 0,2, and 4 -for %even from 0 to 5 by 2 +for %even in 0 to 5 by 2 say "Even #\%even" -for %backwards from 3 to 1 by -1 +for %backwards in 3 to 1 by -1 say "Backwards #\%backwards" # How do I do a 'while' loop? @@ -289,7 +285,7 @@ if (1 > (TWENTY)) on opposite day # Well... it's always *possible* to fall back to Lua behavior for something like this: action [best of %items according to %key_fn] <- {%best:nil, %best_key:nil} - for all %items + for % in %items %key <- (=lua "\%key_fn(\%)") if: (%best is (nil)) or (%key > %best_key) <- {%best:%, %best_key:%key} @@ -312,7 +308,7 @@ immediately parse [best of %items according to %key_expr] as result of <- {%best:nil, %best_key:nil} - for all %items + for % in %items %key <- %key_expr if: (%best is (nil)) or (%key > %best_key) <- {%best:%, %best_key:%key} -- cgit v1.2.3