summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-03-14 13:27:06 -0700
committerKaz Kylheku <kaz@kylheku.com>2012-03-14 13:27:06 -0700
commit0592949de3e274b7d9700ec74466b541055c3bca (patch)
tree7782121888bf42e1719834cf23594b51bb3ce4a4 /eval.c
parent96f072cfdb5d1eac3e32dbdb15704b0a32258a37 (diff)
downloadtxr-0592949de3e274b7d9700ec74466b541055c3bca.tar.gz
txr-0592949de3e274b7d9700ec74466b541055c3bca.tar.bz2
txr-0592949de3e274b7d9700ec74466b541055c3bca.zip
Allow quasi-quoting over hash table literals,
to express dynamic hash table construction * eval.c (expand_qquote): Recognize hash-construct forms: expand the hash arguments and pairs separately, then rewrite to a new hash-construct form. (eval-init): hash-construct intrinsic function added. * hash.c (hash_construct_s): New symbol variable. (hash_construct): New function. (hash_init): Initialize hash_construct_s. * hash.h (hash_construct_s, hash_construct): Declared. * parser.y (hash): Rule rewritten to emit either a literal hash table object, or a hash-construct form, based on whether quasiquote unquotes occur within the syntax. (hash_from_notation): Function removed.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/eval.c b/eval.c
index 156e58e2..b87f23c5 100644
--- a/eval.c
+++ b/eval.c
@@ -1383,6 +1383,10 @@ static val expand_qquote(val qquoted_form)
} else if (sym == qquote_s) {
return rlcp(expand_qquote(expand_qquote(second(qquoted_form))),
qquoted_form);
+ } else if (sym == hash_construct_s) {
+ val args = expand_qquote(second(qquoted_form));
+ val pairs = expand_qquote(rest(rest(qquoted_form)));
+ return rlcp(list(sym, args, pairs, nao), qquoted_form);
} else {
val f = car(qquoted_form);
val r = cdr(qquoted_form);
@@ -2196,6 +2200,7 @@ void eval_init(void)
reg_fun(intern(lit("make-hash"), user_package), func_n3(make_hash));
reg_fun(intern(lit("hash"), user_package), func_n0v(hashv));
+ reg_fun(intern(lit("hash-construct"), user_package), func_n2(hash_construct));
reg_fun(gethash_s, func_n3o(gethash_n, 2));
reg_fun(intern(lit("sethash"), user_package), func_n3(sethash));
reg_fun(intern(lit("pushhash"), user_package), func_n3(pushhash));