aboutsummaryrefslogtreecommitdiff
path: root/examples/sample_code.nom
diff options
context:
space:
mode:
Diffstat (limited to 'examples/sample_code.nom')
-rw-r--r--examples/sample_code.nom85
1 files changed, 57 insertions, 28 deletions
diff --git a/examples/sample_code.nom b/examples/sample_code.nom
index 561a3c8..f8315a8 100644
--- a/examples/sample_code.nom
+++ b/examples/sample_code.nom
@@ -7,13 +7,11 @@ require "lib/core.nom"
say "foo"
-say (4)
+say (-4 + (1.5 - .25))
-#.. "rule" is just a function that takes a function call spec and a block of code to run,
+#.. "rule" is just a macro that takes a function call spec and a block of code to run,
and stores the function definition
-rule: fart ..=: say "poot"
-
-fart
+rule [fart] =: say "poot"
# multi-line strings:
say ".."
@@ -23,23 +21,28 @@ say ".."
|long string
|
- | with
+ | with
| rather
- | silly
+ | silly # fake comments and
+ # Real comments look like this
| indentation
| and "quotes"
|.." (even fakeouts like that) "
|(done)
+ |
+ |^and trailing spaces
|
-rule: doublefart ..=: # this farts twice
+say ".."|Longstrings have interpolation: \1 + 2\ <- like that
+
+rule [doublefart] =: # this farts twice
say "poot"
say "poot"
doublefart
-rule: subex work ..=: "subexpressions work"
+rule [subex work] =: "subexpressions work"
say (subex work)
@@ -54,9 +57,9 @@ say [..]
1, 2
3
-rule: say both %one and %two ..=:
- say %one
- say %two
+rule [say both %1 and %2] =:
+ say %1
+ say %2
say both [..]
1,2
@@ -64,24 +67,21 @@ say both [..]
3,4
-say both..
- "hello"
- and "world"
-
-rule: three ..=: 3
-say both ..
- "a list:"
- and [..]
- 1,2,(three),(4)
+rule [three] =: 3
+say both
+.."a list:"
+..and [..]
+ 1,2,three,4
if 1: yes
..else: no
-if 1: yes ..else: no
+if 1 (:yes) else (:no)
say (do: return: 5)
-rule: do %one also %two ..=:
+# Some variables
+rule [do %one also %two] =:
do %one
do %two
@@ -92,9 +92,38 @@ say (do: return: "wow")
say (1 + (-(2 * 3)))
-say (2 + (..)
- 3 * 4
-..)
+say (..)
+ 2 + (..)
+ 3 * 4
+
+when:
+ when %x == 1:
+ say "one"
+ when %x == 2:
+ say "two"
+ when %x:
+ say "nonzero"
+ else:
+ say "???"
+
+when:
+ * %x == 1:
+ say "one"
+ * %x == 2:
+ say "two"
+ * %x:
+ say "nonzero"
+ *:
+ say "???"
+
+when %x ==:
+ * 1:
+ say "one"
+ * 2:
+ say "two"
+ *:
+ say "???"
+
if %x:
say "one"
@@ -110,7 +139,7 @@ say ".."
| with multiple lines
| and an interpolated expression: \2 + 5\
-rule: %n bottles ..=:
+rule [%n bottles] =:
lua block ".."
|do
| print("running raw lua code...")
@@ -122,7 +151,7 @@ rule: %n bottles ..=:
nil
9 bottles
-rule: dumsum %nums ..=:
+rule [dumsum %nums] =:
%sum =: 0
for %n in %nums:
%sum +=: %n