munificent / lark
Lark is a weird little hybrid of Scheme and SmallTalk. And C.
Clone this repository (size: 392.2 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/munificent/lark/
| commit 23: | 5a1839f4cf6b |
| parent 22: | 082ec4bddacd |
| branch: | default |
Tests for def:is: and global:is:. do creates local scope.
Changed (Δ482 bytes):
raw changeset »
src/com/stuffwithstuff/lark/SpecialForms.java (6 lines added, 2 lines removed)
test/def.lark (21 lines added, 0 lines removed)
test/global.lark (16 lines added, 0 lines removed)
Up to file-list src/com/stuffwithstuff/lark/SpecialForms.java:
| … | … | @@ -16,15 +16,19 @@ public class SpecialForms { |
16 |
16 |
public static CallableExpr doForm() { |
17 |
17 |
return new CallableExpr() { |
18 |
18 |
public Expr call(Interpreter interpreter, Scope scope, Expr argExpr) { |
19 |
||
20 |
// create a new local scope for the body |
|
21 |
Scope local = scope.create(); |
|
22 |
||
19 |
23 |
// if the arg isn't a list, just eval it normally |
20 |
if (!(argExpr instanceof ListExpr)) return interpreter.eval( |
|
24 |
if (!(argExpr instanceof ListExpr)) return interpreter.eval(local, argExpr); |
|
21 |
25 |
|
22 |
26 |
// evaluate each item in the arg list in order, returning the last one |
23 |
27 |
ListExpr argList = (ListExpr)argExpr; |
24 |
28 |
|
25 |
29 |
Expr result = null; |
26 |
30 |
for (Expr arg : argList.getList()) { |
27 |
result = interpreter.eval( |
|
31 |
result = interpreter.eval(local, arg); |
|
28 |
32 |
} |
29 |
33 |
|
30 |
34 |
return result; |
