Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

More stuff, also badly hacked, like multiple function arguments...

  • Loading branch information...
commit f3259baf059db32590e87f9c4d7bde9dc3307cc8 1 parent ee941d5
Harold authored
12 helloworld.mun
@@ -12,3 +12,15 @@
12 12 ]
13 13 [print [square 5]]
14 14 [print [square [square 5]]]
  15 +[print [head '["abc" 2 3]]]
  16 +[define add
  17 + [lambda [a b]
  18 + [+ a b]
  19 + ]
  20 +]
  21 +[print [add 6 7]]
  22 +[print [add [square 2] [square 3]]]
  23 +[print [head '["abc" 1 2 3]]]
  24 +[print [tail '[999 0]]]
  25 +[print [head [join 1 2]]]
  26 +[print [tail [join 1 2]]]
16 support/bootstrap.lua
@@ -11,6 +11,22 @@ defineFunction( runtime.GLOBAL, '*', 'globalWithValues', function( inContext, in
11 11 return inValueList.head * inValueList.tail.head
12 12 end )
13 13
  14 +defineFunction( runtime.GLOBAL, '+', 'globalWithValues', function( inContext, inValueList )
  15 + return inValueList.head + inValueList.tail.head
  16 +end )
  17 +
  18 +defineFunction( runtime.GLOBAL, 'head', 'globalWithValues', function( inContext, inValueList )
  19 + return inValueList.head.head
  20 +end )
  21 +
  22 +defineFunction( runtime.GLOBAL, 'tail', 'globalWithValues', function( inContext, inValueList )
  23 + return inValueList.head.tail.head
  24 +end )
  25 +
  26 +defineFunction( runtime.GLOBAL, 'join', 'globalWithValues', function( inContext, inValueList )
  27 + return runtime.join( inValueList.head, inValueList.tail )
  28 +end )
  29 +
14 30 defineFunction( runtime.GLOBAL, 'print', 'globalWithValues', function( inContext, inValueList )
15 31 local theValuePair = inValueList
16 32 while theValuePair do
10 support/runtime.lua
@@ -134,8 +134,7 @@ function apply( inRunnable, inArgList )
134 134 return inRunnable( theContext, inArgList )
135 135 elseif isPair( inRunnable ) then
136 136 local theContext = createContext( inRunnable.tail.tail.tail.head )
137   - -- TODO: generalize this for more than one argument
138   - theContext[ inRunnable.tail.head.head.head.symbol ] = inArgList.head
  137 + augmentContext( theContext, inRunnable.tail.head.head, inArgList )
139 138 return eval( theContext, inRunnable.tail.head.tail, "apply!" )
140 139 else
141 140 print( "WARNING (This used to be an error?): WTF KIND OF RUNNABLE IS THIS? ("..tostring(inRunnable)..")" )
@@ -151,5 +150,12 @@ function makeDefinition( inContext, inList )
151 150 runtime.set( inContext, inList.tail.head.symbol, eval( inContext, inList.tail.tail.head, "makeDefinition" ) )
152 151 end
153 152
  153 +function augmentContext( inContext, inArgNameList, inArgValueList )
  154 + inContext[ inArgNameList.head.symbol ] = inArgValueList.head
  155 + if inArgNameList.tail then
  156 + augmentContext( inContext, inArgNameList.tail, inArgValueList.tail )
  157 + end
  158 +end
  159 +
154 160 GLOBAL = createContext( )
155 161

0 comments on commit f3259ba

Please sign in to comment.
Something went wrong with that request. Please try again.