From af791d39068b7cd231497f955c0a314a31ee8881 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 17 Dec 2013 07:15:44 -0800 Subject: * 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. --- ChangeLog | 7 +++++++ eval.c | 9 +++------ txr.1 | 45 +++++++++++++++++++++++++++++++++++++++++++++ 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 + + * 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 * 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 ) + +.TP +Description: + +The defvar operator binds a variable in the top-level environment. + +If the variable named already exists in the top-level environment, the +form has no effect; the 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 form. The 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 : ) + +.TP +Description: + +The lisp-parse function converts text denoting TXR Lisp structure, into the +corresponding data structure. The 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 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 -- cgit v1.2.3