summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2013-12-17 07:15:44 -0800
committerKaz Kylheku <kaz@kylheku.com>2013-12-17 07:15:44 -0800
commitaf791d39068b7cd231497f955c0a314a31ee8881 (patch)
tree2134a7c919a06bc5b71844e05ac547df6b40d41d
parent0c5016a7f39a6a70018949da90f3b9737bf945de (diff)
downloadtxr-af791d39068b7cd231497f955c0a314a31ee8881.tar.gz
txr-af791d39068b7cd231497f955c0a314a31ee8881.tar.bz2
txr-af791d39068b7cd231497f955c0a314a31ee8881.zip
* eval.c (op_defvar): Fix the semantics to be similar to Common Lisp:
no effect if the variable already exists. * txr.1: Documented defvar and lisp-parse.
-rw-r--r--ChangeLog7
-rw-r--r--eval.c9
-rw-r--r--txr.145
3 files changed, 55 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index ddc5238a..acb32b2a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2013-12-17 Kaz Kylheku <kaz@kylheku.com>
+
+ * eval.c (op_defvar): Fix the semantics to be similar to Common Lisp:
+ no effect if the variable already exists.
+
+ * txr.1: Documented defvar and lisp-parse.
+
2013-12-16 Kaz Kylheku <kaz@kylheku.com>
* lib.c (intern): fix the previous diagnostic bug once more with more
diff --git a/eval.c b/eval.c
index 3c4aa120..c0adfa0c 100644
--- a/eval.c
+++ b/eval.c
@@ -721,13 +721,10 @@ static val op_defvar(val form, val env)
eval_error(form, lit("let: ~s is not a bindable sybol"), sym, nao);
{
- val value = eval(second(args), env, form);
- val existing = gethash(top_vb, sym);
-
- if (existing)
- set(*cdr_l(existing), value);
- else
+ if (!gethash(top_vb, sym)) {
+ val value = eval(second(args), env, form);
sethash(top_vb, sym, cons(sym, value));
+ }
}
return sym;
diff --git a/txr.1 b/txr.1
index 511a1551..0249f684 100644
--- a/txr.1
+++ b/txr.1
@@ -5576,6 +5576,29 @@ table, depending on the type of obj.
.SH BINDING AND ITERATION
+.SS Operator defvar
+
+.TP
+Syntax:
+
+ (defvar <sym> <value>)
+
+.TP
+Description:
+
+The defvar operator binds a variable in the top-level environment.
+
+If the variable named <sym> already exists in the top-level environment, the
+form has no effect; the <value> form is not evaluated, and the value of the
+variable is unchanged.
+
+If the variable does not exist, then it is introduced, with a value given by
+evaluating the <value> form. The <value> form is evaluated in the environment
+in which the defvar form occurs, not necessarily in the top-level environment.
+
+The symbols t and nil may not be used as variables, and neither
+can be keyword symbols: symbols denoted by a leading colon.
+
.SS Operators let and let*
.TP
@@ -10378,6 +10401,7 @@ the two operations will interfere with the UTF-8 decoding.
These functions return nil when the end of data is reached. Errors are
represented as exceptions.
+
.SS Functions put-string, put-line, put-char and put-byte
.TP
@@ -10488,6 +10512,27 @@ the stream-real-time-p function above), and also for setting the priority at
which messages are reported to syslog by the *stdlog* stream (see *stdlog*
in the UNIX SYSLOG section).
+.SS Function lisp-parse
+
+.TP
+Syntax:
+
+ (lisp-parse <source> : <error-stream>)
+
+.TP
+Description:
+
+The lisp-parse function converts text denoting TXR Lisp structure, into the
+corresponding data structure. The <source> argument may be either a character
+string, or a stream. The source must provide the syntax of one complete Lisp
+object, without any stray tokens after that object.
+
+The optional <error-stream> argument can be used to specify a stream to which
+parse errors diagnostics are sent. If absent, the diagnostics are suppressed.
+
+If there are parse errors, the function returns nil; otherwise, it returns the
+parsed data structure.
+
.SH FILESYSTEM ACCESS
.SS Function stat