Re: (loop initially ... getting non-ANSI CL warning
- From: Mirko.Vukovic@xxxxxxxxx
- Date: Wed, 23 Jan 2008 08:41:15 -0800 (PST)
On Jan 22, 5:46 am, Mirko.Vuko...@xxxxxxxxx wrote:
Hi,
I am still in a bit of shock that my first loop attempt works, with
one legalistic exception.
This is my simple code to show duplicates in a list:
(defun show-duplicates (list)
(loop
initially with ref = (first list)
for entry in (rest list) do
(if (equal ref entry)
(print entry))
(setf ref entry)))
Using clisp on windows+cygwin+emacs+slime, I get the following warning
upon compilation:
WARNING: LOOP: missing forms after INITIALLY: permitted by CLtL2,
forbidden by
ANSI CL.
The code seems to work:
CL-USER> (show-duplicates '(1 3 4 5 5 7 8 12 12 12 15))
5
12
12
NIL
CL-USER> (can-it-be-improved-p)
T
I could not find examples that would show me the problem with my
"initially" form.
To remove the warning, I can use
(loop initially (setf ref (first list)) ...
but that gives me a warning about ref not being defined or bound.
So, what is the right way to do that?
Thanks,
Mirko
First, thanks to everyone, especially for sample codes.
Second, I was not clear in my original post, but Ken caught it: I am
parsing an ordered list.
Third, one day (soon?) I may give up on "loop" and switch to "iterate"
Since I really want to collect the duplicates, I went with Ken's
approach:
(defun collect-duplicates (list)
(loop
for a in list
for b in (cdr list)
when (equal a b)
collect b))
It eliminates the (setf ...), and I must admit, the setf just did not
look right in the loop. But I could not think of another way of doing
it.
Mirko
.
- Follow-Ups:
- References:
- (loop initially ... getting non-ANSI CL warning
- From: Mirko . Vukovic
- (loop initially ... getting non-ANSI CL warning
- Prev by Date: Re: emacs + windows + graphics
- Next by Date: Re: the necessity of Lisp's Objects?
- Previous by thread: Re: (loop initially ... getting non-ANSI CL warning
- Next by thread: Re: (loop initially ... getting non-ANSI CL warning
- Index(es):
Relevant Pages
|
|