Skip to content

Commit

Permalink
not allowing free variables, anymore -- too many errors; you have to …
Browse files Browse the repository at this point in the history
…quote strings
  • Loading branch information
zot committed Apr 23, 2012
1 parent 733078b commit 91429a4
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 34 deletions.
16 changes: 9 additions & 7 deletions TODO.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ <h1>TODO</h1>
<li>parser macros should return (ast, errors, warnings)</li>
<li>error if let/do has no expr</li>
<li>error if let finds more than one body expr</li>
<li>debug mode should put a cons into funcs of a new error and the list from the parent
<ul>
<li>can use this to see the origin of a thunk</li>
</ul></li>
<li>add assertMonad() to testing.cs
<ul>
<li>probably use env for this</li>
Expand Down Expand Up @@ -63,21 +67,19 @@ <h1>TODO</h1>
<li>comments that attach event handlers?</li>
<li>make TTT into a notebook that shows the TTT grid</li>
<li>optionally hide source code</li>
<li>load/save</li>
</ul></li>
<li>better browser environment
<li>a 'require' directive that works in browsers and on the cmd line
<ul>
<li>left side should be an editor</li>
<li>loading files should load them into the editor</li>
<li>input should be in a blinking box on the right side, not in an alert box</li>
<li>should be able to load *.lsr files into the environment</li>
<li>adding a script tag works in browsers, provided you're not violating access restrictions (the launch script can help with that)</li>
</ul></li>
<li>use curlies for do/let
<li>use curlies for do/let?
<ul>
<li>not sure what this means for indentation</li>
<li>remove intermediate step of inserting {}; -- convert directly to parenthesized groups</li>
<li>allow newlines in open groups</li>
<li>{ and } would be a grouping macros</li>
</ul></li>
<li>debug mode should put a cons into funcs of a new exception and the list from the parent</li>
<li>add prelude.lsr
<ul>
<li>put parser macros in there</li>
Expand Down
14 changes: 7 additions & 7 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* parser macros should return (ast, errors, warnings)
* error if let/do has no expr
* error if let finds more than one body expr
* debug mode should put a cons into funcs of a new error and the list from the parent
* can use this to see the origin of a thunk
* add assertMonad() to testing.cs
* probably use env for this
* pretty printer function can take an assoc-list of printers for types
Expand Down Expand Up @@ -34,16 +36,14 @@
* comments that attach event handlers?
* make TTT into a notebook that shows the TTT grid
* optionally hide source code
* better browser environment
* left side should be an editor
* loading files should load them into the editor
* input should be in a blinking box on the right side, not in an alert box
* should be able to load *.lsr files into the environment
* use curlies for do/let
* load/save
* a 'require' directive that works in browsers and on the cmd line
* adding a script tag works in browsers, provided you're not violating access restrictions (the launch script can help with that)
* use curlies for do/let?
* not sure what this means for indentation
* remove intermediate step of inserting {}; -- convert directly to parenthesized groups
* allow newlines in open groups
* { and } would be a grouping macros
* debug mode should put a cons into funcs of a new exception and the list from the parent
* add prelude.lsr
* put parser macros in there
* integrate physics engine
Expand Down
7 changes: 6 additions & 1 deletion leisure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ class Code
code = code.copyWith(nameSub val).reffedValue(deref)
if vars.find((v)-> v == val) then code.addVar(val)
else if ctx[nameSub(val)]? or code.global.find((v)-> v == val) then code
else code.copyWith(JSON.stringify(scanTok(val))).unreffedValue(deref)
#else code.copyWith(JSON.stringify(scanTok(val))).unreffedValue(deref)
else if typeof val == 'number' then code.copyWith(JSON.stringify(scanTok(val))).unreffedValue(deref)
else
console.log "FREE: #{val}, type: #{typeof val}"
code.addErr "attempt to use free variable: #{val}"
when 'lit'
val = getLitVal ast
src = if typeof val == 'function' or typeof val == 'object'
Expand Down Expand Up @@ -542,6 +546,7 @@ continueApply tag(apply(laz(func))(laz(arg)), func.leisureStart, arg.leisureEnd)
try
l = JSON.parse(name)
if typeof l == 'string' then lit(laz(l))
else if typeof l == 'number' then ref(laz(l))
else ref(laz(name))
catch err
ref(laz(name))
Expand Down
7 changes: 6 additions & 1 deletion leisure.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,11 @@ misrepresented as being the original software.
return v === val;
})) {
return code;
} else {
} else if (typeof val === 'number') {
return code.copyWith(JSON.stringify(scanTok(val))).unreffedValue(deref);
} else {
console.log("FREE: " + val + ", type: " + (typeof val));
return code.addErr("attempt to use free variable: " + val);
}
}
break;
Expand Down Expand Up @@ -1000,6 +1003,8 @@ misrepresented as being the original software.
l = JSON.parse(name);
if (typeof l === 'string') {
return lit(laz(l));
} else if (typeof l === 'number') {
return ref(laz(l));
} else {
return ref(laz(name));
}
Expand Down
18 changes: 9 additions & 9 deletions testLeisure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ 3. This notice may not be removed or altered from any source distribution.

run 'test1', -> assertParse("1", "ref 1")
run 'test2', -> assertParse("\\x.x x y", "lambda x . apply (apply (ref x) (ref x)) (ref y)", "\\x.x x y")
run 'test3', -> assertEval("(\\x . x) hello", 'hello')
run 'test4', -> assertEval("eval (apply (lambda x (ref x)) (lit hello))", 'hello')
run 'test5', -> assertEval("(eq cons cons) yes no", 'yes')
run 'test6', -> assertEval("(eq cons true) yes no", 'no')
run 'test3', -> assertEval("(\\x . x) 'hello'", 'hello')
run 'test4', -> assertEval("eval (apply (lambda 'x' (ref 'x')) (lit 'hello'))", 'hello')
run 'test5', -> assertEval("(eq cons cons) 'yes' 'no'", 'yes')
run 'test6', -> assertEval("(eq cons true) 'yes' 'no'", 'no')
run 'test7', -> LZ.astEval(LZ.gen(LZ.parse("cons 1 2")))
run 'test8', -> LZ.astEval(LZ.gen(LZ.parse("head (cons 1 2)")))
run 'test9', -> assertEval("head (cons 1 2)", 1)
run 'test10', -> assertEval("tail (cons 1 2)", 2)
run 'test11', -> assertEval("last (cons a nil)", 'a')
run 'test12', -> assertEval("last (cons a (cons b nil))", 'b')
run 'test13', -> assertEval("(is (cons a b) cons) yes no", 'yes')
run 'test14', -> assertEval("(eval (lambda a (lambda b (ref a)))) yes no", 'yes')
run 'test15', -> assertEval("(\\1 .; 1) hello", 'hello')
run 'test11', -> assertEval("last (cons 'a' nil)", 'a')
run 'test12', -> assertEval("last (cons 'a' (cons 'b' nil))", 'b')
run 'test13', -> assertEval("(is (cons 'a' 'b') cons) 'yes' 'no'", 'yes')
run 'test14', -> assertEval("(eval (lambda 'a' (lambda 'b' (ref 'a')))) 'yes' 'no'", 'yes')
run 'test15', -> assertEval("(\\1 .; 1) 'hello'", 'hello')
run 'test16', -> assertEval("head ([ 1 ])", 1)
run 'test17', -> assertEval("head (tail (append ([ 1 ]) ([ 2 ])))", 2)
run 'test18', -> assertEval("head [1]", 1)
Expand Down
18 changes: 9 additions & 9 deletions testLeisure.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ Tests for Leisure
});

run('test3', function() {
return assertEval("(\\x . x) hello", 'hello');
return assertEval("(\\x . x) 'hello'", 'hello');
});

run('test4', function() {
return assertEval("eval (apply (lambda x (ref x)) (lit hello))", 'hello');
return assertEval("eval (apply (lambda 'x' (ref 'x')) (lit 'hello'))", 'hello');
});

run('test5', function() {
return assertEval("(eq cons cons) yes no", 'yes');
return assertEval("(eq cons cons) 'yes' 'no'", 'yes');
});

run('test6', function() {
return assertEval("(eq cons true) yes no", 'no');
return assertEval("(eq cons true) 'yes' 'no'", 'no');
});

run('test7', function() {
Expand All @@ -91,23 +91,23 @@ Tests for Leisure
});

run('test11', function() {
return assertEval("last (cons a nil)", 'a');
return assertEval("last (cons 'a' nil)", 'a');
});

run('test12', function() {
return assertEval("last (cons a (cons b nil))", 'b');
return assertEval("last (cons 'a' (cons 'b' nil))", 'b');
});

run('test13', function() {
return assertEval("(is (cons a b) cons) yes no", 'yes');
return assertEval("(is (cons 'a' 'b') cons) 'yes' 'no'", 'yes');
});

run('test14', function() {
return assertEval("(eval (lambda a (lambda b (ref a)))) yes no", 'yes');
return assertEval("(eval (lambda 'a' (lambda 'b' (ref 'a')))) 'yes' 'no'", 'yes');
});

run('test15', function() {
return assertEval("(\\1 .; 1) hello", 'hello');
return assertEval("(\\1 .; 1) 'hello'", 'hello');
});

run('test16', function() {
Expand Down

0 comments on commit 91429a4

Please sign in to comment.