diff options
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | eval.c | 3 | ||||
-rw-r--r-- | lib.c | 8 | ||||
-rw-r--r-- | lib.h | 1 | ||||
-rw-r--r-- | txr.1 | 29 |
5 files changed, 47 insertions, 9 deletions
@@ -1,5 +1,20 @@ 2014-02-17 Kaz Kylheku <kaz@kylheku.com> + * eval.c (eval_init): Register gensym function as the gensym + intrinsic, rather than gensymv. + Register gensym_counter as *gensym-counter*. + + * lib.c (gensym): Handle missing prefix argument by defaulting + the prefix to "g". + (gensymv): Function removed. + + * lib.h (gensymv): Declaration removed. + + * txr.1: Fixed omission: missing documentation for gensym. + Documented *gensym-counter*. + +2014-02-17 Kaz Kylheku <kaz@kylheku.com> + * eval.c (expand): Bugfix: do not expand any part of the macro form via expand_forms. This is completely wrong since only the macro knows what material is evaluated and what isn't. @@ -2964,7 +2964,8 @@ void eval_init(void) reg_var(intern(lit("*keyword-package*"), user_package), &keyword_package); reg_var(intern(lit("*system-package*"), user_package), &system_package); reg_fun(intern(lit("make-sym"), user_package), func_n1(make_sym)); - reg_fun(intern(lit("gensym"), user_package), func_n0v(gensymv)); + reg_fun(intern(lit("gensym"), user_package), func_n1o(gensym, 0)); + reg_var(intern(lit("*gensym-counter*"), user_package), &gensym_counter); 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)); @@ -2703,18 +2703,12 @@ val make_sym(val name) val gensym(val prefix) { + prefix = default_arg(prefix, lit("g")); val name = format(nil, lit("~a~,04a"), prefix, gensym_counter = plus(gensym_counter, one), nao); return make_sym(name); } -val gensymv(val args) -{ - uses_or2; - val prefix = or2(car(args), lit("g")); - return gensym(prefix); -} - val make_package(val name) { if (find_package(name)) { @@ -555,7 +555,6 @@ val compl_span_str(val str, val set); val break_str(val str, val set); val make_sym(val name); val gensym(val prefix); -val gensymv(val args); val make_package(val name); val packagep(val obj); val find_package(val name); @@ -11734,6 +11734,35 @@ does not belong to any package (it is said to be "uninterned"). Note: an uninterned symbol can be interned into a package with the rehome-sym function. Also see the intern function. +.SS Function gensym + +.TP +Syntax: + + (gensym [<prefix>]) + +Description + +The gensym function is similar to make-sym. It creates and returns a new +symbol object. If the <prefix> argument is omitted, it defaults to "g". +Otherwise it must be a string. + +The difference between gensym and make-sym is that gensym creates the name +by combining the prefix with a numeric suffix. + +The numeric sufix is a decimal digit string, taken from the value of +the variable *gensym-counter*, after incrementing it. + +Note: the variation in name is not the basis of the uniqueness of gensym; the +basis of its uniqueness is that it is a freshly instantiated object. make-sym +also returns unique symbols even if repeatedly called with the same string. + +.SS Variable *gensym-counter* + +This variable is initialized to 0. Each time the gensym function is called, +it is incremented. The incremented value forms the basis of the numeric +suffix which gensym uses to form the name of the new symbol. + .SS Function make-package .TP |