aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-06-20 15:23:03 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-06-20 15:23:10 -0700
commit7761f715f7497e8b325a4f1134869f332848fd16 (patch)
treef966e85a6ba2d838c4d4a1981e206dd0d78995e5 /examples
parentd73cbf0aa5c9081d965e06822f4958aa5c1871e6 (diff)
Cleaning up examples.
Diffstat (limited to 'examples')
-rw-r--r--examples/how_do_i.nom71
1 files changed, 0 insertions, 71 deletions
diff --git a/examples/how_do_i.nom b/examples/how_do_i.nom
index 867405b..c6c7ba3 100644
--- a/examples/how_do_i.nom
+++ b/examples/how_do_i.nom
@@ -364,74 +364,3 @@ say: best of [2,-3,4,-8] where %x has score (%x * %x)
multiplication. In addition to being more efficient, it's also more powerful and
flexible for the language to allow you to define syntax that manipulates expressions.
- For example, list comprehensions can (and are) easily defined in Nomsu as:
-
-parse [%expr for %key-var in %list] as
- result of
- %result <- []
- for %key-var in %list
- add %expr to %result
- return %result
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-%double-nums <- ((2 * %num) for %num in [1,2,3,4,5])
-
-
-# Naturally, Nomsu's macros are hygienic, so even though "%result" is used as a local
- variable in the macro, there won't be any namespace collisions or confusion if you
- use a different variable named "%result" as any (or all) of the arguments to the macro.
-
-%result <- [1,2,3,4]
-%result <- ((2*%result) for %result in %result)
-assume: %result = [2,4,6,8]
-
-# You'll find that in a lot places where a functional programmer would think to use a
- lambda function, what they actually want to do is some metaprogramming. If you embrace
- the metaprogramming from the start, then you can do a lot more powerful stuff.
-
-# For example, you can define a loop that operates on recursive datastructures, but still
- has all of the normal imperative control structures:
-
-compile [stack for %var] to
- Lua value "stack\(%var as lua id)"
-
-parse [recurse on %sub as %super] as
- add %sub to (stack for %super)
-
-parse [for %var in recursive %iterable %body] as
- with {(stack for %var): [%iterable]}
- repeat while: (length of (stack for %var)) > 0
- %var <- (remove index 1 from (stack for %var))
- with {%val: %expr}
- if: %val != (nil)
- add %val to %result
- %body
- === next %var ===
- === stop %var ===
-
-~~~~~~~~~~~~~~~~
-
-# This action iterates over a recursive structure, but it's written imperatively and it
- can return early without traversing the whole tree.
-action [tree %tree contains %val]
- for %subtree in recursive %tree
- if: %subtree = %val
- return: yes
- if: (type of %subtree) = "table"
- for % in %subtree: recurse on % as %subtree
- return: no
-
-%t <- [1,[2,[3,4,[]],5,[6]]]
-say: tree %t contains 3
-say: tree %t contains 99
-
-
-action [linked list from %list]
- %head <- (nil)
- for %i in (length of %list) to 1 via -1
- %head <- {value:%list.%i, next:%head}
- return %head
-
-for %node in recursive (linked list from [3,4,5,6,7])
- say "NODE: \(%node.value)"
- recurse on %node.next as %node