Does the Common Lisp spec say anything about whether the following is
well defined given that the elements of "list" are unique:
(loop for x in list
when (p x)
do (setq list (delete x list)))
-- Jeff Barnett
Jeff Barnett wrote:
> Does the Common Lisp spec say anything about whether the following is
> well defined given that the elements of "list" are unique:
>
> (loop for x in list
> when (p x)
> do (setq list (delete x list)))
See http://www.lispworks.com/documentation/HyperSpec/Body/03_f.htm
But I wouldn't worry too much and just switch to a non-destructive version:
(loop for x in list
unless (p x) collect x into new-list
finally (setq list new-list))
Pascal
--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
Pascal Costanza wrote:
> Jeff Barnett wrote:
>> Does the Common Lisp spec say anything about whether the following is
>> well defined given that the elements of "list" are unique:
>>
>> (loop for x in list
>> when (p x)
>> do (setq list (delete x list)))
>
> See http://www.lispworks.com/documentation/HyperSpec/Body/03_f.htm
>
> But I wouldn't worry too much and just switch to a non-destructive
> version:
>
> (loop for x in list
> unless (p x) collect x into new-list
> finally (setq list new-list))
>
>
> Pascal
>
That of course would not be equivalent to what I wrote and asked about.
There may be other pointers to list or some of its eventual cdrs. The
basic question is can (extended) loop be used to write certain
destructive primitives or must we revert to the "machine language" parts
of Lisp? At the time the standards were being formed, this question was
well discussed. When I looked to see what was written now days, the
literature was mute on the topic.
-- Jeff Barnett
(message (Hello 'Jeff)
(you :wrote :on '(Wed, 30 May 2007 22:45:37 -0700))
(
JB> Does the Common Lisp spec say anything about whether the following is
JB> well defined given that the elements of "list" are unique:
JB> (loop for x in list
JB> when (p x)
JB> do (setq list (delete x list)))
i suspect it won't work right, but it's very confusing and very inefficient
anyway.
what's about one of this:
(delete-if #'p list)
(loop for x in lisp unless (p x) collect x)
(mapcan (lambda (x) (unless (p x) (list x))) list)
)
(With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
"I am everything you want and I am everything you need")