aboutsummaryrefslogtreecommitdiff
path: root/game1.moon
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2017-08-16 05:19:08 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2017-08-16 05:19:08 -0700
commitf6ab7587e1d036aa0a0c97ec0f82f66220ed3bdd (patch)
tree5fc36d7e102fe7aeb6a179493eab1d5c0191aab7 /game1.moon
parent3dc68105e1699a8ef43857b5c26a4ad08cc4c5b9 (diff)
Much more cleanup. Now it's much easier to write mostly nomic code.
Diffstat (limited to 'game1.moon')
-rwxr-xr-xgame1.moon99
1 files changed, 20 insertions, 79 deletions
diff --git a/game1.moon b/game1.moon
index f17222e..ace0f00 100755
--- a/game1.moon
+++ b/game1.moon
@@ -1,100 +1,41 @@
#!/usr/bin/env moon
-nomic = require 'nomic'
-game = nomic()
-
------------------- CORE STUFF ---------------------
-game\def [[say $str]], (locals)=>
- with locals
- print(.str)
- return nil
-
-game\def [[return $retval]], (locals)=> locals.retval
-
-game\def [[do $thunk]], (locals)=>
- locals.thunk\run(@, locals)
-
-game\def {[[true]], [[yes]]}, (locals)=> true
-game\def {[[false]], [[no]]}, (locals)=> false
-game\def {[[nil]], [[None]], [[nop]], [[done]]}, (locals)=> nil
-
-game\def [[$x == $y]], (locals)=>
- with locals
- print("testing equality of #{.x} and #{.y}")
- if type(.x) != type(.y)
- return false
- if type(.x) == 'table'
- for k,v in pairs(.x)
- if .y[k] != v
- return false
- for k,v in pairs(.y)
- if .x[k] != v
- return false
- return true
- else
- return .x == .y
-
-game\def [[not $x]], (locals)=> not locals.x
-game\def [[$x != $y]], [[return (not (x == y))]]
-game\def [[$x < $y]], (locals)=> locals.x < locals.y
-game\def [[$x <= $y]], (locals)=> locals.x <= locals.y
-game\def [[$x > $y]], (locals)=> locals.x > locals.y
-game\def [[$x >= $y]], (locals)=> locals.x >= locals.y
-
-
-game\def [[if $condition then $body else $else_body]], (locals)=>
- with locals
- if .condition
- return .body\run(@, locals)
- else return .else_body\run(@, locals)
-
-game\def [[if $condition then $body]], [[if $condition then $body else {}]]
-game\def [[when $condition do $body]], [[if $condition then $body else {}]]
-
+game = require 'core'
+export __DEBUG__
+__DEBUG__ = true
------------------ BASIC TESTS ---------------------
-
-game\run [[say "Hello world!"]]
game\run [[
- say "Hello!"
- say "World!"
-]]
-game\def {[[greet]], [[say hello]]}, [[say "Hello!"]]
-game\run[[greet]]
-game\run[[say hello]]
+say "=========== INITIALIZING GAME ============"
-game\run [["ping" := {say "pong"}]]
-game\run [[ping]]
+"fart" := {say "poot"}
+fart
-game\run [[say (return "returned value")]]
+"fart twice" := {
+ fart
+ fart
+}
-game\run [[do {say "did"}]]
+fart twice
-game\run [[say 5]]
-game\run [[say -5]]
+["greet", "say hello"] := { say "Hello!" }
+greet
-game\def [[fart]], [[say "poot"]]
-game\run [[fart]]
-game\def [[fart twice]], [[
- say "poot"
- say "poot again"
-]]
-game\run [[fart twice]]
+say (return "returned value")
+do {say "did"}
+say 6
+say -6
+say [1,2,3]
-game\def [[sum $items]], (locals)=>
- tot = 0
- for x in *locals.items do tot += x
- return tot
+]]
+error("done")
game\run "say [1,2,3]"
game\run "sum [1,2,3]"
game\run "say (sum [1,2,3])"
-game\def [[print $x]], [[say $x]]
-game\run [[print "printing variables works"]]
-
game\def [[you]], (_)=> @you
game\run [[you]]