summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog15
-rw-r--r--eval.c3
-rw-r--r--lib.c8
-rw-r--r--lib.h1
-rw-r--r--txr.129
5 files changed, 47 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index f96c18b3..b64d2beb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/eval.c b/eval.c
index 719f007b..cae7bd74 100644
--- a/eval.c
+++ b/eval.c
@@ -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));
diff --git a/lib.c b/lib.c
index b1e8b39f..e74d2a6d 100644
--- a/lib.c
+++ b/lib.c
@@ -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)) {
diff --git a/lib.h b/lib.h
index 32d26eb3..0c5e2445 100644
--- a/lib.h
+++ b/lib.h
@@ -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);
diff --git a/txr.1 b/txr.1
index 2ccb8338..fb40e7f1 100644
--- a/txr.1
+++ b/txr.1
@@ -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