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.
Robert Nystrom / munificent
7 weeks ago

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(scope, argExpr);
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(scope, arg);
31
                    result = interpreter.eval(local, arg);
28
32
                }
29
33
                
30
34
                return result;

Up to file-list test/def.lark:

1
# output: ()
2
# output: 1
3
# output: 2
4
# output: 3
5
# output: 1
6
7
print a;
8
9
def: a is: 1;
10
print a;
11
12
# create a local scope
13
{
14
    def: a is: 2;
15
    print a;
16
    
17
    def: a is: 3;
18
    print a;
19
};
20
21
print a;

Up to file-list test/global.lark:

1
# output: ()
2
# output: 123
3
# output: 345
4
# output: 345
5
6
print a;
7
8
global: a is: 123;
9
print a;
10
11
{
12
    global: a is: 345;
13
    print a;
14
};
15
16
print a;