HCoop
/
jackhill
/
mal.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Change quasiquote algorithm
[jackhill/mal.git]
/
process
/
stepA_mal.txt
diff --git
a/process/stepA_mal.txt
b/process/stepA_mal.txt
index
1b67f95
..
1f3ac41
100644
(file)
--- a/
process/stepA_mal.txt
+++ b/
process/stepA_mal.txt
@@
-3,7
+3,6
@@
import types, reader, printer, env, core
READ(str): return reader.read_str(str)
READ(str): return reader.read_str(str)
-pair?(ast): return ... // true if non-empty sequence
quasiquote(ast): return ... // quasiquote
macro?(ast, env): return ... // true if macro call
quasiquote(ast): return ... // quasiquote
macro?(ast, env): return ... // true if macro call
@@
-21,7
+20,8
@@
EVAL(ast,env):
if not list?(ast): return eval_ast(ast, env)
ast = macroexpand(ast, env)
if not list?(ast): return eval_ast(ast, env)
ast = macroexpand(ast, env)
- if not list?(ast): return ast
+ if not list?(ast): return eval_ast(ast, env)
+ if empty?(ast): return ast
switch ast[0]:
'def!: return env.set(ast[1], EVAL(ast[2], env))
switch ast[0]:
'def!: return env.set(ast[1], EVAL(ast[2], env))
@@
-51,9
+51,8
@@
repl_env.set('*ARGV*, cmdline_args[1..])
;; core.mal: defined using the language itself
rep("(def! *host-language* \"racket\")")
rep("(def! not (fn* (a) (if a false true)))")
;; core.mal: defined using the language itself
rep("(def! *host-language* \"racket\")")
rep("(def! not (fn* (a) (if a false true)))")
-rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))")
+rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \"
\nnil
)\")))))")
rep("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))");
rep("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))");
-rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))");
if cmdline_args: rep("(load-file \"" + args[0] + "\")"); exit 0
if cmdline_args: rep("(load-file \"" + args[0] + "\")"); exit 0
@@
-79,10
+78,14
@@
ns = {'=: equal?,
'nil?: nil?,
'true?: true?,
'false?: false?,
'nil?: nil?,
'true?: true?,
'false?: false?,
+ 'string?: string?,
'symbol: symbol,
'symbol?: symbol?,
'keyword: keyword,
'keyword?: keyword?,
'symbol: symbol,
'symbol?: symbol?,
'keyword: keyword,
'keyword?: keyword?,
+ 'number?: number?,
+ 'fn?: fn?,
+ 'macro?: macro?,
'pr-str: (a) -> a.map(|s| pr_str(e,true)).join(" ")),
'str: (a) -> a.map(|s| pr_str(e,false)).join("")),
'pr-str: (a) -> a.map(|s| pr_str(e,true)).join(" ")),
'str: (a) -> a.map(|s| pr_str(e,false)).join("")),
@@
-118,6
+121,7
@@
ns = {'=: equal?,
'sequential? sequential?,
'cons: (a) -> concat([a[0]], a[1]),
'concat: (a) -> reduce(concat, [], a),
'sequential? sequential?,
'cons: (a) -> concat([a[0]], a[1]),
'concat: (a) -> reduce(concat, [], a),
+ 'vec: (l) -> l converted to vector,
'nth: (a) -> a[0][a[1]] OR raise "nth: index out of range",
'first: (a) -> a[0][0] OR nil,
'rest: (a) -> a[0][1..] OR list(),
'nth: (a) -> a[0][a[1]] OR raise "nth: index out of range",
'first: (a) -> a[0][0] OR nil,
'rest: (a) -> a[0][1..] OR list(),
@@
-127,6
+131,7
@@
ns = {'=: equal?,
'map: map,
'conj: conj,
'map: map,
'conj: conj,
+ 'seq: seq,
'meta: (a) -> a[0].meta,
'with-meta: (a) -> a[0].with_meta(a[1]),
'meta: (a) -> a[0].meta,
'with-meta: (a) -> a[0].with_meta(a[1]),