From d8f9b15fd9da8c9ae29ee0b63c4302e5efbde387 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 31 Dec 2018 01:02:46 -0800 Subject: [PATCH] Cleaning up some of the documentation and dead code. --- compatibility/3.nom | 2 +- compatibility/4.11.nom | 4 ++-- core/errors.nom | 12 ---------- core/id.nom | 2 +- core/math.nom | 50 ---------------------------------------- core/metaprogramming.nom | 5 ++-- examples/how_do_i.nom | 26 ++++++++++----------- tools/parse.nom | 2 +- tools/test.nom | 2 +- 9 files changed, 21 insertions(+), 84 deletions(-) diff --git a/compatibility/3.nom b/compatibility/3.nom index 3b58cee..0a745f6 100644 --- a/compatibility/3.nom +++ b/compatibility/3.nom @@ -12,4 +12,4 @@ upgrade action (@) to "3" as $me upgrade action "as" to "3" via for $tree: compile error at $tree "Object API has changed and 'as' is no longer supported." - "Use (%obj::action ...) instead of (as %obj: action ...)" + "Use ($obj, action ...) instead of (as $obj: action ...)" diff --git a/compatibility/4.11.nom b/compatibility/4.11.nom index 313b8e4..a5c9c12 100644 --- a/compatibility/4.11.nom +++ b/compatibility/4.11.nom @@ -16,7 +16,7 @@ upgrade action "call 1 with" to "4.11" via return (SyntaxTree $tree2) upgrade action (-> $yield_value) to "4.11" as (yield $yield_value) -# Replace set {%x:1, %y:2} with [%x, %y] = [1, 2] +# Replace set {$x:1, $y:2} with [$x, $y] = [1, 2] upgrade action "set" to "4.11" via for ($tree $end_version): [$lhs, $rhs] = [\[], \[]] @@ -33,7 +33,7 @@ upgrade action "set" to "4.11" via upgrade action "1 with 2 ~>" to "4.11" via for $tree: compile error at $tree "This method has been deprecated." - "Perhaps this could be use %tree::map instead." + "Perhaps this could be use ($tree, map ...) instead." # Changing filesystem API: upgrade action (for file $f in $path $body) to "4.11" as diff --git a/core/errors.nom b/core/errors.nom index 6a773a7..6779922 100644 --- a/core/errors.nom +++ b/core/errors.nom @@ -88,21 +88,9 @@ test: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# - [..] - try %action and if it succeeds %success or if it barfs %fallback - try %action and if it barfs %fallback or if it succeeds %success - ..all parse as (..) - try %action and if it succeeds %success or if it barfs (=lua "") %fallback - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - (try $action) parses as try $action and if it succeeds (do nothing) or if it barfs (do nothing) -#(try %action and if it barfs %fallback) parses as (..) - try %action and if it succeeds (do nothing) or if it barfs %fallback - (try $action and if it barfs $msg $fallback) parses as try $action and if it succeeds (do nothing) or if it barfs $msg $fallback diff --git a/core/id.nom b/core/id.nom index a22df25..d5f747a 100644 --- a/core/id.nom +++ b/core/id.nom @@ -54,7 +54,7 @@ externally (uuid) means: $bytes.4 += 0xC0 return (=lua "('%08x-%04x-%04x-%02x%02x-%6x%6x'):format(unpack(\$bytes))") -# For strict identity checking, use (%x's id) == (%y's id) +# For strict identity checking, use ($x's id) == ($y's id) test: assume (([] == []) and ((id of []) != (id of []))) seed random with 0 diff --git a/core/math.nom b/core/math.nom index adba0e9..04388cb 100644 --- a/core/math.nom +++ b/core/math.nom @@ -72,38 +72,12 @@ externally [all of $items, all $items] all mean: unless $: return (no) return (yes) - -#[all of %items, all %items] all compile to: - unless (%items.type is "List"): - return \(all of %items) - - if ((size of %items) == 0): - return (Lua "true") - - %lua = (Lua "(") - %lua::add [: for % in %items: add (% as lua expr)] joined with " and " - %lua::add ")" - return %lua - [not all of $items, not all $items] all parse as (not (all of $items)) externally [any of $items, any $items] all mean: for $ in $items: if $: return (yes) return (no) - -#[any of %items, any %items] all compile to: - unless (%items.type is "List"): - return \(any of %items) - - if ((size of %items) == 0): - return (Lua "false") - - %lua = (Lua "(") - %lua::add [: for % in %items: add (% as lua expr)] joined with " or " - %lua::add ")" - return %lua - [none of $items, none $items] all parse as (not (any of $items)) # Sum/product @@ -113,36 +87,12 @@ externally [sum of $items, sum $items] all mean: $total += $ return $total -#[sum of %items, sum %items] all compile to: - unless (%items.type is "List"): - return \(sum of %items) - - if ((size of %items) == 0): - return (Lua "0") - - %lua = (Lua "(") - %lua::add [: for % in %items: add (% as lua expr)] joined with " + " - %lua::add ")" - return %lua - externally [product of $items, product $items] all mean: $prod = 1 for $ in $items: $prod *= $ return $prod -#[product of %items, product %items] all compile to: - unless (%items.type is "List"): - return \(product of %items) - - if ((size of %items) == 0): - return (Lua "1") - - %lua = (Lua "(") - %lua::add [: for % in %items: add (% as lua expr)] joined with " * " - %lua::add ")" - return %lua - externally [avg of $items, average of $items] all mean (sum of $items) / (size of $items) diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom index a9eabd0..2e1bf6b 100644 --- a/core/metaprogramming.nom +++ b/core/metaprogramming.nom @@ -210,11 +210,11 @@ test: [$1, $2] = [1, 2] swap $1 and $2 assume (($1 == 2) and ($2 == 1)) or barf - "'parse % as %' failed on 'swap % and %'" + "'parse $ as $' failed on 'swap $ and $'" [$tmp, $tmp2] = [1, 2] swap $tmp and $tmp2 assume (($tmp == 2) and ($tmp2 == 1)) or barf - "'parse % as %' variable mangling failed." + "'parse $ as $' variable mangling failed." ($actions all parse as $body) compiles to: lua> (" @@ -266,7 +266,6 @@ test: [$action parses as $body] all parse as ([$action] all parse as $body) -#(%tree as lua expr) compiles to "compile(\(=lua "compile(\%tree, true)"), true)" externally ($tree as lua expr) means: lua> (" local tree_lua = compile(\$tree) diff --git a/examples/how_do_i.nom b/examples/how_do_i.nom index c48b137..e3c58d6 100644 --- a/examples/how_do_i.nom +++ b/examples/how_do_i.nom @@ -18,7 +18,7 @@ use "lib" say "Hello world!" # How do I set a variable? -# Variables have "%" prefix: +# Variables have "$" prefix: $foobar = 1 $text = "Hello world" @@ -50,7 +50,7 @@ $multi_text = (" say (" Text can contain a backslash followed by a variable, list, dict, or parenthesized expression. This escaped value will be converted to readable text, like so: - The value of %foobar is \$foobar, isn't that nice? + The value of $foobar is \$foobar, isn't that nice? These are some numbers: \[1, 2, 3] The sum of 2 and 4 is \(2 + 4). @@ -58,7 +58,7 @@ say (" like this: \\ will just be treated as a backslash. Or, two backlashes will be treated as a single backslash, no matter what follows, - like this: \\%foobar <- won't insert any values + like this: \\$foobar <- won't insert any values If you need to split a long line without inserting a newline, you can end a line with backslash \ ..and start the next line with two periods, like that. @@ -139,12 +139,12 @@ if (1 + 2) is: # How do I loop over a list (a foreach loop)? $list = [1, 2, 3] for $x in $list: - say "For %x loop #\$x" + say "For $x loop #\$x" # How do I loop over a number range? # This is inclusive, so it will loop over 1,2, and 3 for $i in 1 to 3: - say "For %i in 1 to 3 loop #\$i" + say "For $i in 1 to 3 loop #\$i" # This will print 0,2, and 4 for $even in 0 to 5 by 2: @@ -247,28 +247,28 @@ say (2 + 3) say (2 + 3) # If you need to keep going after an indented region, you can start the next line with ".." -say both "Very long first argument that needs its own line" and also - "short second arg" +say both "Very very very very long first argument that needs its own line" +..and also "short second arg" (my favorite number) means (21 + 2) # This can be nested: say both (my favorite number) and also "foo" # Macros: -# The "lua> %" and "=lua %" macros can be used to write raw lua code: +# The "lua>" and "=lua" macros can be used to write raw lua code: (say the time) means: lua> "io.write(\"The OS time is: \", os.time(), \"\\n\");" say the time say "Math expression result is: \(=lua "(1 + 2*3 + 3*4)^2 % 5")" -# Variables can be accessed via \%var +# Variables can be accessed via \$var (square root of $n) means (=lua "math.sqrt(\$n)") say "The square root of 2 is \(square root of 2)" -# Macros can be defined to transform one bit of nomsu code into another using "parse % as %": +# Macros can be defined to transform one bit of nomsu code into another using "parse $ as $": (if $condition is untrue $body) parses as (if (not $condition) $body) -# Or to transform nomsu code into custom lua code using "compile % to %" +# Or to transform nomsu code into custom lua code using "compile $ to $" (debug only $body) compiles to: if $DEBUG_ENABLED: return @@ -310,10 +310,10 @@ debug only: $best_key = $key return $best -# Function literals look like: %x -> (%x * %x) +# Function literals look like: $x -> ($x * $x) say (best of [2, -3, 4, -8] according to ($x -> ($x * $x))) -# Or, you can use ((foo %)'s meaning) to access the function that gets called by (foo %) +# Or, you can use ((foo $)'s meaning) to access the function that gets called by (foo $) ($x squared) means ($x * $x) say (best of [2, -3, 4, -8] according to (($ squared)'s meaning)) diff --git a/tools/parse.nom b/tools/parse.nom index d28c80c..ac9c42f 100755 --- a/tools/parse.nom +++ b/tools/parse.nom @@ -24,7 +24,7 @@ externally (print tree $t at indent $indent) means: say "\$indent\($t.1)" "Var": - say "\($indent)%\($t.1)" + say "\($indent)$\($t.1)" else: say "\$indent\($t.type):" diff --git a/tools/test.nom b/tools/test.nom index a2cd992..67afb96 100755 --- a/tools/test.nom +++ b/tools/test.nom @@ -1,6 +1,6 @@ #!/usr/bin/env nomsu -V6.13.12.8 # - Tool to run all tests in a file (i.e. the code block inside a call to 'test %'). Usage: + Tool to run all tests in a file (i.e. the code block inside a call to 'test $'). Usage: nomsu tools/test.nom file1 file2 directory1 ... use "lib/os.nom"