1 if (typeof module
!== 'undefined') {
2 var types
= require('./types');
3 var readline
= require('./node_readline');
4 var reader
= require('./reader');
5 var printer
= require('./printer');
10 return reader
.read_str(str
);
14 function eval_ast(ast
, env
) {
15 if (types
._symbol_Q(ast
)) {
17 } else if (types
._list_Q(ast
)) {
18 return ast
.map(function(a
) { return EVAL(a
, env
); });
19 } else if (types
._vector_Q(ast
)) {
20 var v
= ast
.map(function(a
) { return EVAL(a
, env
); });
21 v
.__isvector__
= true;
23 } else if (types
._hash_map_Q(ast
)) {
26 new_hm
[EVAL(k
, env
)] = EVAL(ast
[k
], env
);
34 function _EVAL(ast
, env
) {
35 //printer.println("EVAL:", printer._pr_str(ast, true));
36 if (!types
._list_Q(ast
)) {
37 return eval_ast(ast
, env
);
41 var el
= eval_ast(ast
, env
), f
= el
[0];
42 return f
.apply(f
, el
.slice(1));
45 function EVAL(ast
, env
) {
46 var result
= _EVAL(ast
, env
);
47 return (typeof result
!== "undefined") ? result
: null;
52 return printer
._pr_str(exp
, true);
57 var rep = function(str
) { return PRINT(EVAL(READ(str
), repl_env
)); };
59 repl_env
['+'] = function(a
,b
){return a
+b
;};
60 repl_env
['-'] = function(a
,b
){return a
-b
;};
61 repl_env
['*'] = function(a
,b
){return a
*b
;};
62 repl_env
['/'] = function(a
,b
){return a
/b
;};
65 if (typeof require
!== 'undefined' && require
.main
=== module
) {
66 // Synchronous node.js commandline mode
68 var line
= readline
.readline("user> ");
69 if (line
=== null) { break; }
71 if (line
) { printer
.println(rep(line
)); }
73 if (exc
instanceof reader
.BlankException
) { continue; }
74 if (exc
.stack
) { printer
.println(exc
.stack
); }
75 else { printer
.println(exc
); }