Re: checking implementation defined and implementation dependent behaviour
- From: Juho Snellman <jsnell@xxxxxx>
- Date: 27 Apr 2007 23:49:43 GMT
Joerg Hoehle <hoehle@xxxxxxxxxxxxxxxxxxxxx> wrote:
;; Whether the iteration constructs establish a new binding of var on
;; each iteration or whether it establishes a binding for var once at
;; the beginning and then assigns it on any subsequent iterations
;; Actually, CLISP does not guarantee the (3 3 3) or (2 2 2) result,
;; it just guarantees that it won't be (2 1 0), but rather (x x x),
;; because a single binding is assigned on each iteration.
(let (a)
(dotimes (i 3) (push (lambda () i) a))
(loop for x in a collect (funcall x)))
#+(or clisp cmu sbcl cormanlisp) (3 3 3)
#+(or) (2 1 0)
CMUCL 19d was changed to return (2 1 0) for this. I think it was due
to pedantically reading the following part of the spec:
dotimes evaluates count-form, which should produce an integer. If
count-form is zero or negative, the body is not executed. dotimes
then executes the body once for each integer from 0 up to but not
including the value of count-form
as requiring the iteration count to always be constant, whether or not
the iteration variable is changed. That is, the interpretation is that
the following should return 5, not 1:
(let ((x 0))
(dotimes (i 5 x)
(incf x)
(setf i 5)))
For which the most reasonable, though not only, implementation is to
rebind the variable on every iteration.
--
Juho Snellman
.
- References:
- checking implementation defined and implementation dependent behaviour
- From: Joerg Hoehle
- checking implementation defined and implementation dependent behaviour
- Prev by Date: Re: What are the domains that lisp doesn't fit int?
- Next by Date: Re: What are the domains that lisp doesn't fit int?
- Previous by thread: checking implementation defined and implementation dependent behaviour
- Next by thread: Re: checking implementation defined and implementation dependent behaviour
- Index(es):
Relevant Pages
|