aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2017-10-07 16:38:13 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2017-10-07 16:38:13 -0700
commit6a429d79558f70578ba30565f5ae299f0fe42da1 (patch)
treea41494d6993d69c731c9dfac0d51de4d23ad2501
parentb7973b0afa3b5ab4df803bc102cd0f3f4b8db671 (diff)
Added "unless" to core.
-rw-r--r--examples/how_do_i.nom8
-rw-r--r--lib/control_flow.nom6
2 files changed, 9 insertions, 5 deletions
diff --git a/examples/how_do_i.nom b/examples/how_do_i.nom
index 6e6219a..4d667cf 100644
--- a/examples/how_do_i.nom
+++ b/examples/how_do_i.nom
@@ -250,20 +250,20 @@ rule [square root of %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 %":
-parse [unless %condition %body] as:
+parse [if %condition is untrue %body] as:
if (not %condition): %body
# Or to transform nomsu code into custom lua code using "compile % to code %"
-compile [unless2 %condition %body] to code: ".."
+compile [if %condition on opposite day %body] to code: ".."
|if not (\(%condition as lua)) then
| \(%body as lua statements)
|end
-unless (1 > 10):
+if (1 > 10) is untrue:
say "Nomsu parsing macros work!"
say "It looks like a keyword, but there's no magic here!"
-unless2 (1 > 10):
+if (1 > 10) on opposite day:
say "Lua compiling macros work!"
say "It looks like a keyword, but there's no magic here!"
diff --git a/lib/control_flow.nom b/lib/control_flow.nom
index c4d6900..6287bfb 100644
--- a/lib/control_flow.nom
+++ b/lib/control_flow.nom
@@ -7,8 +7,12 @@ compile [if %condition %if_body] to code: ".."
|if \(%condition as lua) then;
| \(%if_body as lua statements)
|end;
+compile [unless %condition %body] to code: ".."
+ |if not (\(%condition as lua)) then;
+ | \(%body as lua statements)
+ |end;
-compile [if %condition %if_body else %else_body] to code: ".."
+compile [if %condition %if_body else %else_body, unless %condition %else_body else %if_body] to code: ".."
|if \(%condition as lua) then;
| \(%if_body as lua statements)
|else;