summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-01-21 07:05:09 -0800
committerKaz Kylheku <kaz@kylheku.com>2015-01-21 07:05:09 -0800
commit88b8fc8e07da83b7874df661f05eda37067ed95b (patch)
treeb860ea135cd2f6cc075b34aef723b06e41012f3b /eval.c
parent9797d4dfa53344f9fb2d6f0cab9a4bb0d8225335 (diff)
downloadtxr-88b8fc8e07da83b7874df661f05eda37067ed95b.tar.gz
txr-88b8fc8e07da83b7874df661f05eda37067ed95b.tar.bz2
txr-88b8fc8e07da83b7874df661f05eda37067ed95b.zip
Allow macros to tell what symbols have lexical function
or variable bindings. * eval.c (lexical_var_p, lexical_fun_p): New local functions. (eval_init): Registered as intrinsics. * txr.1: Documented lexical-var-p and lexical-fun-p. * tl.vim, txr.vim: Updated.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/eval.c b/eval.c
index 429d9352..1089c6b8 100644
--- a/eval.c
+++ b/eval.c
@@ -273,6 +273,40 @@ static val lookup_symac(val menv, val sym)
}
}
+static val lexical_var_p(val menv, val sym)
+{
+ if (nilp(menv)) {
+ return nil;
+ } else {
+ type_check(menv, ENV);
+
+ {
+ val binding = assoc(sym, menv->e.vbindings);
+
+ if (binding) /* special_s: see make_var_shadowing_env */
+ return c_true(cdr(binding) == special_s);
+ return lexical_var_p(menv->e.up_env, sym);
+ }
+ }
+}
+
+static val lexical_fun_p(val menv, val sym)
+{
+ if (nilp(menv)) {
+ return nil;
+ } else {
+ type_check(menv, ENV);
+
+ {
+ val binding = assoc(sym, menv->e.fbindings);
+
+ if (binding) /* special_s: see make_var_shadowing_env */
+ return c_true(cdr(binding) == special_s);
+ return lexical_fun_p(menv->e.up_env, sym);
+ }
+ }
+}
+
static void mark_special(val sym)
{
sethash(special, sym, t);
@@ -3815,6 +3849,8 @@ void eval_init(void)
reg_fun(intern(lit("make-env"), user_package), func_n3o(make_env_intrinsic, 0));
reg_fun(intern(lit("env-fbind"), user_package), func_n3(env_fbind));
reg_fun(intern(lit("env-vbind"), user_package), func_n3(env_vbind));
+ reg_fun(intern(lit("lexical-var-p"), user_package), func_n2(lexical_var_p));
+ reg_fun(intern(lit("lexical-fun-p"), user_package), func_n2(lexical_fun_p));
reg_fun(chain_s, func_n0v(chainv));
reg_fun(chand_s, func_n0v(chandv));
reg_fun(intern(lit("juxt"), user_package), func_n0v(juxtv));