Re: (loop initially ... getting non-ANSI CL warning



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
.



Relevant Pages

  • (loop initially ... getting non-ANSI CL warning
    ... I am still in a bit of shock that my first loop attempt works, ... (if (equal ref entry) ... I get the following warning ...
    (comp.lang.lisp)
  • Re: (loop initially ... getting non-ANSI CL warning
    ... I get the following warning ... WARNING: LOOP: missing forms after INITIALLY: permitted by CLtL2, ... but that gives me a warning about ref not being defined or bound. ... for entry in do ...
    (comp.lang.lisp)
  • Re: (loop initially ... getting non-ANSI CL warning
    ... I am still in a bit of shock that my first loop attempt works, ... (if (equal ref entry) ... I get the following warning ... UNIFICATION> (defun show-duplicates (list &optional uniques) ...
    (comp.lang.lisp)
  • Re: 2.6.16-rc1-mm4
    ... >>> WARNING: Loop detected: ... >>> WARNING: Module ... That kgdb stub is slowly deteriorating as everyone hacks on everything else. ... To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ ...
    (Linux-Kernel)
  • Re: Warning: mysql_fetch_array(): 5 is not a valid MySQL result resource
    ... I'm using while loop in all other cases without error or warning. ... Petr Vileta, Czech republic ...
    (comp.lang.php)