summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-11-08 21:09:45 -0800
committerKaz Kylheku <kaz@kylheku.com>2016-11-08 21:09:45 -0800
commit847a7b6c5292bd2126303e3ab7a6916657e13a71 (patch)
tree35e76797d42dbdae9171ab436f492e754576cf78 /eval.c
parent3ccdd5c9bfc6c8a8812ef6dab12dc1a1cd2bc0ee (diff)
downloadtxr-847a7b6c5292bd2126303e3ab7a6916657e13a71.tar.gz
txr-847a7b6c5292bd2126303e3ab7a6916657e13a71.tar.bz2
txr-847a7b6c5292bd2126303e3ab7a6916657e13a71.zip
Implement *package* special var; package overhaul.
* eval.c (load): Rebind *package* in the local dynamic environment already established for the sake of *load-path*. By doing this we cause *package* to be restored to its prior value, which allows the loaded file to alter it. Common Lisp works this way. (eval_init): Register *package* variable, with the user package as its default value. * lib.c (package_s): New symbol variable. (intern, rehome_sym): Default the package argument to the current package, not to user_package. (get_user_package, get_system_package, get_keyword_package): Functions removed. (get_current_package): New function. (obj_print_impl): Revise symbol printing. Keyword and uninterned symbols are printed with : and #: prefixes. The remainder are printed with a package prefix if their home package isn't the current package. * lib.h (keyword_package, user_package, system_package): These macros are just straight aliases for the global variables, not going through the lookup mechanism, which was pointless. (cur_package): New macro. (package_s): Declared. (get_current_package): Declared. * lisplib.c (lisplib_try_load): Establish a local dynamic environment, and bind the *package* variable to the user package which the library modules expect. * parser.c (find_matching_syms, provide_completions): Treat unqualified symbols in the current package rather than user package. * parser.y (sym_helper): Intern unqualified symbols in the current package, not user package. * txr.1: Document that the variables user-package, system-package and keyword-package should not be modified. Document the *package* special variable, and that intern and rehome-sym default their package argument to its value. (Here we get rid of wrong references to the undocumented variable *user-package*).
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/eval.c b/eval.c
index c3392acd..e649af91 100644
--- a/eval.c
+++ b/eval.c
@@ -3398,6 +3398,7 @@ val load(val target)
dyn_env = make_env(nil, nil, dyn_env);
env_vbind(dyn_env, load_path_s, path);
+ env_vbind(dyn_env, package_s, cur_package);
if (!read_eval_stream(stream, std_error, nil)) {
close_stream(stream, nil);
@@ -5203,6 +5204,7 @@ void eval_init(void)
reg_fun(intern(lit("make-sym"), user_package), func_n1(make_sym));
reg_fun(intern(lit("gensym"), user_package), func_n1o(gensym, 0));
reg_var(gensym_counter_s = intern(lit("*gensym-counter*"), user_package), zero);
+ reg_var(package_s = intern(lit("*package*"), user_package), user_package_var);
reg_fun(intern(lit("make-package"), user_package), func_n1(make_package));
reg_fun(intern(lit("find-package"), user_package), func_n1(find_package));
reg_fun(intern(lit("delete-package"), user_package), func_n1(delete_package));