aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-03-14 16:30:43 -0700
committerBruce Hill <bruce@bruce-hill.com>2019-03-14 16:30:43 -0700
commitddb839bfd4ba8dbdd214f3e885629fc8fe57e68c (patch)
treeaee183d005229b21a5ce636685f416f97bd5aa9e
parent7f138199078a2fc2b6d6ee8d31da940120c8216a (diff)
Replacing (size of $) with (#$) as should have been done before.
-rw-r--r--lib/base64/init.nom10
-rw-r--r--lib/compatibility/2.4.nom9
-rw-r--r--lib/compatibility/2.nom5
-rw-r--r--lib/compatibility/4.10.12.7.nom12
-rw-r--r--lib/compatibility/4.8.10.nom10
-rw-r--r--lib/compatibility/4.9.nom5
-rw-r--r--lib/compatibility/compatibility.nom6
-rw-r--r--lib/core/collections.nom13
-rw-r--r--lib/core/control_flow.nom65
-rw-r--r--lib/core/math.nom4
-rw-r--r--lib/core/operators.nom3
-rw-r--r--lib/file_hash/init.nom6
-rwxr-xr-xlib/tools/find.nom4
-rwxr-xr-xlib/tools/repl.nom25
-rwxr-xr-xlib/tools/replace.nom4
-rwxr-xr-xlib/tools/upgrade.nom4
16 files changed, 95 insertions, 90 deletions
diff --git a/lib/base64/init.nom b/lib/base64/init.nom
index a76a49f..5257519 100644
--- a/lib/base64/init.nom
+++ b/lib/base64/init.nom
@@ -4,7 +4,7 @@
https://tools.ietf.org/html/rfc4648
$b64_str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
-$b64_chars = [: for $ in 1 to (size of $b64_str): add ($b64_str, character $)]
+$b64_chars = [: for $ in 1 to (#$b64_str): add ($b64_str, character $)]
$reverse_b64 = {: for $c in $b64_chars at $i: add $c = ($i - 1)}
$reverse_b64."=" = 64
set $reverse_b64's metatable to {.__index = (-> 0)}
@@ -18,10 +18,10 @@ test:
external:
[base64 $str, base64 encode $str, $str base64] all mean:
$chars = []
- for $i in 1 to (size of $str) via 3:
+ for $i in 1 to (#$str) via 3:
$bytes = [=lua "\$str:byte(\$i, \($i + 2))"]
$chars, add $b64_chars.((($bytes.1 & 252) >> 2) + 1)
- if (size of $bytes) is:
+ if (#$bytes) is:
3:
$chars, add $b64_chars.((($bytes.1 & 3) << 4) + (($bytes.2 & 240) >> 4) + 1)
$chars, add $b64_chars.((($bytes.2 & 15) << 2) + (($bytes.3 & 192) >> 6) + 1)
@@ -40,11 +40,11 @@ external:
(chr $) means (=lua "string.char(\$)")
[decode base64 $str, $str base64 decoded, base64 decode $str] all mean:
$chars = []
- for $i in 1 to (size of $str) via 4:
+ for $i in 1 to (#$str) via 4:
$indices = [: for $j in $i to ($i + 3): add $reverse_b64.($str, character $j)]
$chars, add (chr (($indices.1 << 2) + (($indices.2 & 48) >> 4)))
if (($str, character ($i + 2)) == "="): stop
$chars, add (chr ((($indices.2 & 15) << 4) + (($indices.3 & 60) >> 2)))
if (($str, character ($i + 3)) == "="): stop
$chars, add (chr ((($indices.3 & 3) << 6) + $indices.4))
- return ($chars, joined)
+ return ($chars, joined) \ No newline at end of file
diff --git a/lib/compatibility/2.4.nom b/lib/compatibility/2.4.nom
index 953307b..1296777 100644
--- a/lib/compatibility/2.4.nom
+++ b/lib/compatibility/2.4.nom
@@ -10,7 +10,8 @@ upgrade $tree to "2.4" as:
unless ($tree is "Action" syntax tree): return
if $tree.stub is:
"when" "if":
- if ((size of $tree) == 3): return $tree
+ if ((#$tree) == 3):
+ return $tree
$conditions = []
$new_lines = []
$body =
@@ -22,7 +23,7 @@ upgrade $tree to "2.4" as:
$new_lines, add $line
($line.stub == "*"):
- if ((size of $line) == 2):
+ if ((#$line) == 2):
$conditions, add $line.2
..else:
$new_lines, add $line
@@ -60,7 +61,7 @@ upgrade $tree to "2.4" as:
$new_lines, add $line
($line.stub == "*"):
- if ((size of $line) == 2):
+ if ((#$line) == 2):
$values, add $line.2
..else:
$new_lines, add $line
@@ -82,4 +83,4 @@ upgrade $tree to "2.4" as:
.var = ($tree.2 upgraded)
.body =
=lua "SyntaxTree{type='Block', source=\$tree[5].source, unpack(\$new_lines)}"
- }
+ } \ No newline at end of file
diff --git a/lib/compatibility/2.nom b/lib/compatibility/2.nom
index da11245..782ccb0 100644
--- a/lib/compatibility/2.nom
+++ b/lib/compatibility/2.nom
@@ -33,6 +33,5 @@ upgrade $tree to "2" as:
$bits = [: for $ in $tree: add (($ upgraded) if ($ is syntax tree) else $)]
unless (($bits, last) is "Block" syntax tree):
$body = ($bits, last)
- $bits.(size of $bits) =
- =lua "SyntaxTree{type='Block', source=\$body.source, \$body}"
- return (=lua "SyntaxTree{type='Action', source=\$tree.source, unpack(\$bits)}")
+ $bits.(#$bits) = (=lua "SyntaxTree{type='Block', source=\$body.source, \$body}")
+ return (=lua "SyntaxTree{type='Action', source=\$tree.source, unpack(\$bits)}") \ No newline at end of file
diff --git a/lib/compatibility/4.10.12.7.nom b/lib/compatibility/4.10.12.7.nom
index be53cb6..f134476 100644
--- a/lib/compatibility/4.10.12.7.nom
+++ b/lib/compatibility/4.10.12.7.nom
@@ -40,7 +40,7 @@ upgrade action ($k = $v for $i in $start to $stop via $step) to "4.10.12.7" as
{: for $i in $start to $stop by $step: add $k = $v}
upgrade action (parse $text from $filename) to "4.10.12.7" as
- (NomsuCode from (Source $filename 1 (size of $text)) $text) parsed
+ (NomsuCode from (Source $filename 1 (#$text)) $text) parsed
upgrade action ($ as lua statements) to "4.10.12.7" as ($ as lua)
upgrade action (compile error at $pos $err hint $hint) to "4.10.12.7" as
@@ -54,7 +54,7 @@ upgrade $tree to "4.10.12.7" as:
$first_chunk = $tree.1
$i = 1
$has_use = (no)
- repeat while ($i <= (size of $first_chunk)):
+ repeat while ($i <= (#$first_chunk)):
if (($first_chunk.$i.type == "Action") and ($first_chunk.$i.stub == "use")):
$has_use = (yes)
..else:
@@ -69,12 +69,10 @@ upgrade $tree to "4.10.12.7" as:
for $j in 1 to ($i - 1):
$chunk1.$j = $first_chunk.$j
- for $j in $i to (size of $first_chunk):
+ for $j in $i to (#$first_chunk):
$chunk2.($j - $i + 1) = $first_chunk.$j
$new_tree = ("FileChunks" tree from $tree.source with $chunk1 $chunk2)
-
- for $i in 2 to (size of $tree):
+ for $i in 2 to (#$tree):
$new_tree.($i + 1) = $tree.$i
-
- return $new_tree
+ return $new_tree \ No newline at end of file
diff --git a/lib/compatibility/4.8.10.nom b/lib/compatibility/4.8.10.nom
index 15a502b..71d69d0 100644
--- a/lib/compatibility/4.8.10.nom
+++ b/lib/compatibility/4.8.10.nom
@@ -11,7 +11,7 @@ upgrade action "local action" to "4.8.10" via
$body = $tree.4
if $spec.type is:
"List":
- if ((size of $spec) == 1):
+ if ((#$spec) == 1):
return \($spec.1 means $body)
..else:
return \($spec all mean $body)
@@ -26,7 +26,7 @@ upgrade action "action" to "4.8.10" via
if $body:
if $spec.type is:
"List":
- if ((size of $spec) == 1):
+ if ((#$spec) == 1):
return \(externally $spec.1 means $body)
..else:
return \(externally $spec all mean $body)
@@ -42,7 +42,7 @@ upgrade action "compile 1 to" to "4.8.10" via
$body = $tree.4
if $spec.type is:
"List":
- if ((size of $spec) == 1):
+ if ((#$spec) == 1):
return \($spec.1 compiles to $body)
..else:
return \($spec all compile to $body)
@@ -56,7 +56,7 @@ upgrade action "parse 1 as" to "4.8.10" via
$body = $tree.4
if $spec.type is:
"List":
- if ((size of $spec) == 1):
+ if ((#$spec) == 1):
return \($spec.1 parses as $body)
..else:
return \($spec all parse as $body)
@@ -65,4 +65,4 @@ upgrade action "parse 1 as" to "4.8.10" via
return \($spec parse as $body)
upgrade action (compile as $) to "4.8.10" as (what $ compiles to)
-upgrade action (remove action $) to "4.8.10" as (($'s meaning) = (nil))
+upgrade action (remove action $) to "4.8.10" as (($'s meaning) = (nil)) \ No newline at end of file
diff --git a/lib/compatibility/4.9.nom b/lib/compatibility/4.9.nom
index d8260a4..67d40c5 100644
--- a/lib/compatibility/4.9.nom
+++ b/lib/compatibility/4.9.nom
@@ -7,5 +7,6 @@ use "compatibility/compatibility"
upgrade action "if" to "4.9" via
for ($tree $end_version):
- if ((size of $tree) > 2): return $tree
- return \(when $tree.2)
+ if ((#$tree) > 2):
+ return $tree
+ return \(when $tree.2) \ No newline at end of file
diff --git a/lib/compatibility/compatibility.nom b/lib/compatibility/compatibility.nom
index dc21f0b..123f4d9 100644
--- a/lib/compatibility/compatibility.nom
+++ b/lib/compatibility/compatibility.nom
@@ -25,7 +25,7 @@ external:
$lua = (Lua "")
for $action in $actions:
$replacements = {}
- for $i in 1 to (size of $action):
+ for $i in 1 to (#$action):
if ($action.$i is "Var" syntax tree):
$replacements.($action.$i.1) = "\(\$tree as lua id)[\$i]"
define mangler
@@ -74,6 +74,7 @@ external:
if ($ver is "Text"):
return (($ as number) for $ in $ver matching "[0-9]+")
return $ver
+
(Ver $) means:
if ($ is "a List"):
if ($.1 is "Text"):
@@ -83,6 +84,7 @@ external:
if $lib:
return {.lib = $lib, .version = ($ver as version list)}
return {.version = ($ as version list)}
+
$start = (Ver $start_version)
$end = (Ver $end_version)
$end.lib or= $start.lib
@@ -137,4 +139,4 @@ external:
$tree upgraded from ($tree.version or $(NOMSU VERSION)) to $end_version
($tree upgraded) means
- $tree upgraded from ($tree.version or $(NOMSU VERSION)) to $(NOMSU VERSION)
+ $tree upgraded from ($tree.version or $(NOMSU VERSION)) to $(NOMSU VERSION) \ No newline at end of file
diff --git a/lib/core/collections.nom b/lib/core/collections.nom
index 60eee3c..02f9302 100644
--- a/lib/core/collections.nom
+++ b/lib/core/collections.nom
@@ -24,7 +24,7 @@ test:
assume (($list, first) == 1)
assume ($list, has 3)
assume (($list, index of 3) == 3)
- assume ((size of $list) == 5)
+ assume ((#$list) == 5)
$list, add 6
assume (($list, last) == 6)
$list, pop
@@ -36,7 +36,7 @@ test:
# Dict functionality
test:
$dict = {.x = 1, .y = 2, .z = 3}
- assume (size of $dict) == 3
+ assume (#$dict) == 3
assume [: for $k = $v in {.x = 1}: add {.key = $k, .value = $v}] ==
[{.key = "x", .value = 1}]
assume ({.x = 1, .y = 1} + {.y = 10, .z = 10}) == {.x = 1, .y = 11, .z = 10}
@@ -44,13 +44,13 @@ test:
assume ({.x = 1, .y = 1} | {.y = 10, .z = 10}) == {.x = 1, .y = 1, .z = 10}
assume ({.x = 1, .y = 1} & {.y = 10, .z = 10}) == {.y = 1}
assume ({.x = 1, .y = 1} ~ {.y = 10, .z = 10}) == {.x = 1, .z = 10}
-
+
# Set compliments:
assume (~{.x}).y
assume ((~{.x}).x == (nil))
$sc = (~{.x, .y})
$sc.y = 99
-
+
# For now, whether $sc.y == 99 or $sc.y == (yes) is unspecified,
(but the actual behavior is (yes))
assume ($sc.y and (not $sc.x))
@@ -180,6 +180,7 @@ test:
for $ in $r:
$visited, add $
assume ($visited == [1, 3, 5, 7, 9])
+
$range_mt = {
.__type = "a Range"
.__index =
@@ -211,8 +212,7 @@ $range_mt = {
($self.last == $other.last) and ($self.step == $other.step)
.backwards = (for $self ($self.last to $self.first by (- $self.step)))
- .__inext = $(inext)
- .__next = $(inext)
+ .__inext = $(inext), .__next = $(inext)
.as_text =
for $self:
if ($self.step == 1):
@@ -220,6 +220,7 @@ $range_mt = {
..else:
return "(\($self.first) to \($self.last) by \($self.step))"
}
+
$range_mt.reversed = $range_mt.backwards
$range_mt.__unm = $range_mt.backwards
$range_mt.__tostring = $range_mt.as_text
diff --git a/lib/core/control_flow.nom b/lib/core/control_flow.nom
index 21e0618..fafc45d 100644
--- a/lib/core/control_flow.nom
+++ b/lib/core/control_flow.nom
@@ -42,8 +42,8 @@ test:
(else $) compiles to:
at (this tree) fail ("
Compile error: This 'else' is not connected to any 'if' or 'unless' condition.
- Hint: You should probably have a ".." in front of the "else", to indicate \
- ..that it's attached to the previous condition.
+ Hint: You should probably have a ".." in front of the "else", to indicate that it's attached \
+ ..to the previous condition.
")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -164,15 +164,16 @@ test:
(for $var in $iterable $body) compiles to:
unless $var:
at (this tree) fail "No var here"
+
# This uses Lua's approach of only allowing loop-scoped variables in a loop
if (($var.type == "Action") and ($var.stub == "1 =")):
[$key, $value] = [$var.1, $var.3]
..else:
[$key, $value] = [nil, $var]
-
+
unless $value:
at (this tree) fail "No value here"
-
+
# Numeric loop:
if (($iterable.type == "Action") and (($iterable, get stub) == "1 to")):
[$start, $stop] = [$iterable.1, $iterable.3]
@@ -181,13 +182,15 @@ test:
local _start = \($start as lua expr)
for \($value as lua identifier)=_start,\($stop as lua expr) do
")
+
if $key:
$loop, add ("
-
+
local \($key as lua identifier) = \($value as lua identifier) - _start + 1;
")
+
go to (loop set)
-
+
# Numeric loop with step:
if (($iterable.type == "Action") and (($iterable, get stub) == "1 to 2 by")):
[$start, $stop, $step] = [$iterable.1, $iterable.3, $iterable.5]
@@ -196,13 +199,15 @@ test:
local _start, _step = \($start as lua expr), \($step as lua expr);
for \($value as lua identifier)=_start,\($stop as lua expr),_step do
")
+
if $key:
$loop, add ("
-
+
local \($key as lua identifier) = (\($value as lua identifier) - _start)/_step + 1
")
+
go to (loop set)
-
+
# for $ in (...):
if $key:
$loop =
@@ -216,6 +221,7 @@ test:
")
--- (loop set) ---
+
# TODO: don't always wrap in block
$lua =
Lua ("
@@ -236,8 +242,10 @@ test:
$lua, add "\n end"
if ($key and ($body has subtree \(stop $key))):
$lua, add "\n " (\(---stop $key ---) as lua)
+
if ($body has subtree \(stop $value)):
$lua, add "\n " (\(---stop $value ---) as lua)
+
$lua, add "\nend -- for-loop"
$lua, remove free vars [($value as lua identifier, text), $key and ($key as lua identifier, text)]
return $lua
@@ -293,7 +301,6 @@ test:
repeat 5 times:
$x += 1
assume $x == 5
-
(repeat $n times $body) parses as (for (=lua "_i") in (1 to $n by 1) $body)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -325,41 +332,41 @@ test:
for $line in $body:
unless
- (($line.type == "Action") and ((size of $line) >= 2)) and
- $line.(size of $line) is "Block" syntax tree
+ (($line.type == "Action") and ((#$line) >= 2)) and
+ $line.(#$line) is "Block" syntax tree
..:
at $line fail ("
Compile error: Invalid line for the body of an 'if' block.
- Hint: Each line should contain one or more conditional expressions followed \
- ..by a block, or "else" followed by a block.
+ Hint: Each line should contain one or more conditional expressions followed by a block, \
+ ..or "else" followed by a block.
")
- $action = $line.(size of $line)
- if (($line.1 == "else") and ((size of $line) == 2)):
+ $action = $line.(#$line)
+ if (($line.1 == "else") and ((#$line) == 2)):
unless $else_allowed:
at $line fail ("
Compile error: You can't have two 'else' blocks.
Hint: Merge all of the 'else' blocks together.
")
- unless ((size of "\$code") > 0):
+ unless ((#"\$code") > 0):
at $line fail ("
Compile error: You can't have an 'else' block without a preceding condition.
- Hint: If you want the code in this block to always execute, you don't need a \
- ..conditional block around it. Otherwise, make sure the 'else' block comes last.
+ Hint: If you want the code in this block to always execute, you don't need a conditional \
+ ..block around it. Otherwise, make sure the 'else' block comes last.
")
$code, add "\nelse\n " ($action as lua)
$else_allowed = (no)
..else:
$code, add $clause " "
- for $i in 1 to ((size of $line) - 1):
+ for $i in 1 to ((#$line) - 1):
if ($i > 1):
$code, add " or "
$code, add ($line.$i as lua expr)
$code, add " then\n " ($action as lua)
$clause = "\nelseif"
- if ((size of "\$code") == 0):
+ if ((#"\$code") == 0):
at $body fail ("
Compile error: 'if' block has an empty body.
Hint: This means nothing would happen, so the 'if' block should be deleted.
@@ -396,40 +403,40 @@ test:
for $line in $body:
unless
- (($line.type == "Action") and ((size of $line) >= 2)) and
- $line.(size of $line) is "Block" syntax tree
+ (($line.type == "Action") and ((#$line) >= 2)) and
+ $line.(#$line) is "Block" syntax tree
..:
at $line fail ("
Compile error: Invalid line for 'if' block.
Hint: Each line should contain expressions followed by a block, or "else" followed by a block.
")
- $action = $line.(size of $line)
- if (($line.1 == "else") and ((size of $line) == 2)):
+ $action = $line.(#$line)
+ if (($line.1 == "else") and ((#$line) == 2)):
unless $else_allowed:
at $line fail ("
Compile error: You can't have two 'else' blocks.
Hint: Merge all of the 'else' blocks together.
")
- unless ((size of "\$code") > 0):
+ unless ((#"\$code") > 0):
at $line fail ("
Compile error: You can't have an 'else' block without a preceding condition.
- Hint: If you want the code in this block to always execute, you don't need \
- ..a conditional block around it. Otherwise, make sure the 'else' block comes last.
+ Hint: If you want the code in this block to always execute, you don't need a conditional \
+ ..block around it. Otherwise, make sure the 'else' block comes last.
")
$code, add "\nelse\n " ($action as lua)
$else_allowed = (no)
..else:
$code, add $clause " "
- for $i in 1 to ((size of $line) - 1):
+ for $i in 1 to ((#$line) - 1):
if ($i > 1):
$code, add " or "
$code, add "\(mangle "branch value") == " ($line.$i as lua expr)
$code, add " then\n " ($action as lua)
$clause = "\nelseif"
- if ((size of "\$code") == 0):
+ if ((#"\$code") == 0):
at $body fail ("
Compile error: 'if' block has an empty body.
Hint: This means nothing would happen, so the 'if' block should be deleted.
diff --git a/lib/core/math.nom b/lib/core/math.nom
index e2c759a..3aab2b5 100644
--- a/lib/core/math.nom
+++ b/lib/core/math.nom
@@ -94,7 +94,7 @@ external:
$prod *= $
return $prod
- [avg of $items, average of $items] all mean ((sum of $items) / (size of $items))
+ [avg of $items, average of $items] all mean ((sum of $items) / (#$items))
# Min/max
[min of $items, smallest of $items, lowest of $items] all mean:
@@ -207,4 +207,4 @@ external:
..all compile to "math.random(\($low as lua expr), \($high as lua expr))"
[random choice from $elements, random choice $elements, random $elements]
- ..all mean (=lua "\$elements[math.random(#\$elements)]")
+ ..all mean (=lua "\$elements[math.random(#\$elements)]") \ No newline at end of file
diff --git a/lib/core/operators.nom b/lib/core/operators.nom
index d868174..6f1fd78 100644
--- a/lib/core/operators.nom
+++ b/lib/core/operators.nom
@@ -15,8 +15,7 @@ test:
($x <= $y) compiles to "(\($x as lua expr) <= \($y as lua expr))"
($x >= $y) compiles to "(\($x as lua expr) >= \($y as lua expr))"
($a == $b) compiles to "(\($a as lua expr) == \($b as lua expr))"
-[$a not= $b, $a != $b] all compile to
- "(\($a as lua expr) ~= \($b as lua expr))"
+[$a not= $b, $a != $b] all compile to "(\($a as lua expr) ~= \($b as lua expr))"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/lib/file_hash/init.nom b/lib/file_hash/init.nom
index 709c622..bbf1060 100644
--- a/lib/file_hash/init.nom
+++ b/lib/file_hash/init.nom
@@ -47,9 +47,9 @@ if $use_sha1:
(hash $) means:
$bytes = ($, bytes)
$hash = ($bytes.1 << 7)
- for $i in 2 to (size of $bytes):
+ for $i in 2 to (#$bytes):
$hash = ((1000003 * $hash) ~ $bytes.$i)
- $hash = ($hash ~ (size of $bytes))
+ $hash = ($hash ~ (#$bytes))
return "\$hash"
external:
@@ -59,4 +59,4 @@ external:
$file_hash = (hash $contents)
if ($file_hash == $hash):
return $filename
- (hash of file $filename) parses as (hash (read file $filename))
+ (hash of file $filename) parses as (hash (read file $filename)) \ No newline at end of file
diff --git a/lib/tools/find.nom b/lib/tools/find.nom
index db7a2c5..e28681a 100755
--- a/lib/tools/find.nom
+++ b/lib/tools/find.nom
@@ -60,7 +60,7 @@ command line program with $args:
$file = (read file $filename)
unless $file:
fail "File does not exist: \$filename"
- $code = (NomsuCode from ($Source $filename 1 (size of $file)) $file)
+ $code = (NomsuCode from ($Source $filename 1 (#$file)) $file)
try:
$tree = ($code parsed)
..if it fails with $msg:
@@ -96,4 +96,4 @@ command line program with $args:
..else:
sort $results by $ -> $.line
for $ in $results:
- say $.text
+ say $.text \ No newline at end of file
diff --git a/lib/tools/repl.nom b/lib/tools/repl.nom
index 716c899..76b35cb 100755
--- a/lib/tools/repl.nom
+++ b/lib/tools/repl.nom
@@ -15,7 +15,7 @@ external:
You can type in Nomsu code here and hit 'enter' twice to run it.
To exit, type 'exit' or 'quit' and hit enter twice.
")
-
+
(tutorial) means:
(use "tools/tutorial").run_with {.extras = []}
exit
@@ -29,19 +29,18 @@ command line program with $args:
type 'tutorial' to run the tutorial
")
-
+
# Best way I know of to detect the number of return values and only
print if it's >0:
(say results of (*extra arguments*)) means:
$N = (select "#" (*extra arguments*))
- if ($N == 0):
- return
+ if ($N == 0): return
for $ in 1 to $N:
$ret = (select $ (*extra arguments*))
if ($ret is "Text"):
$ret = (quote $ret)
say "\$ret"
-
+
repeat:
say (bright (yellow ">> ")) inline
$buff = []
@@ -50,7 +49,7 @@ command line program with $args:
$line = ($io.read "*L")
say (reset color) inline
if (($line == "\n") or (not $line)):
- if ((size of $buff) > 0):
+ if ((#$buff) > 0):
# clear the line
if $(COLOR ENABLED):
say "\027[1A\027[2K" inline
@@ -58,7 +57,7 @@ command line program with $args:
$buff, add ($line, with "\t" -> " ")
say (dim (yellow ".. ")) inline
--- (run buffer) ---
- if ((size of $buff) == 0): stop
+ if ((#$buff) == 0): stop
$buff = ($buff, joined)
spoof file $buff
try:
@@ -69,14 +68,12 @@ command line program with $args:
unless $tree:
do next
-
+
if ($tree.type == "Comment"):
say (dim "Comment:\($tree.1)")
do next
-
- if ($tree.type != "FileChunks"):
- $tree = [$tree]
-
+
+ if ($tree.type != "FileChunks"): $tree = [$tree]
for $chunk in $tree:
try:
$lua = ($chunk as lua)
@@ -91,7 +88,7 @@ command line program with $args:
$lua, remove free vars
if (load "return \($lua, text)"):
$lua, prepend "return "
-
+
try:
say results of (run $lua)
- ..if it fails with $err: say $err
+ ..if it fails with $err: say $err \ No newline at end of file
diff --git a/lib/tools/replace.nom b/lib/tools/replace.nom
index 314834e..3a56002 100755
--- a/lib/tools/replace.nom
+++ b/lib/tools/replace.nom
@@ -90,7 +90,7 @@ command line program with $args:
$file = (read file $filename)
unless $file:
fail "File does not exist: \$filename"
- $code = (NomsuCode from ($Source $filename 1 (size of $file)) $file)
+ $code = (NomsuCode from ($Source $filename 1 (#$file)) $file)
try:
$tree = ($code parsed)
..if it fails with $msg:
@@ -142,4 +142,4 @@ command line program with $args:
if ((#$replaced) > 0):
write "\($tree2 as nomsu)" to file $filename
..else:
- say ($tree2 as nomsu)
+ say ($tree2 as nomsu) \ No newline at end of file
diff --git a/lib/tools/upgrade.nom b/lib/tools/upgrade.nom
index f4a2b8c..debce62 100755
--- a/lib/tools/upgrade.nom
+++ b/lib/tools/upgrade.nom
@@ -27,7 +27,7 @@ command line program with $args:
unless $file:
fail "File does not exist: \$filename"
$leading_indent = ($file, matching "\n*([ ]*)")
- $code = (NomsuCode from (Source $filename 1 (size of $file)) $file)
+ $code = (NomsuCode from (Source $filename 1 (#$file)) $file)
$tree = ($code parsed $start_version)
$uptree =
$tree upgraded from ($start_version or ($tree.version or $(NOMSU VERSION))) to
@@ -45,4 +45,4 @@ command line program with $args:
say (bright "\$filename will be changed")
else:
- say $text inline
+ say $text inline \ No newline at end of file