diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | eval.c | 9 | ||||
-rw-r--r-- | txr.1 | 45 |
3 files changed, 55 insertions, 6 deletions
@@ -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 @@ -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; @@ -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 |