+ Gerardo Sarria <[EMAIL PROTECTED]>:

| I have an honest question.
| Why this fails?.... because I think is ok. And I know that it says
| that the variable list-result cannot be used in into clause, but I
| read I can do this, and maybe somebody can help me (the backtrace
| doesn't help very much).

Where did you read that?  As far as I understand, WITH creates
variable bindings, and so does INTO.  So you're trying to create two
bindings with the same name, and the loop macro won't allow that.

Delete the WITH clause, and you should be OK.

| * (defvar one 1)
| ONE
| * (loop for item in '(1 2 3)
|     with list-result
|     if (not (eq item one))
|     collect item into list-result
|     finally (return list-result))

Let me add a couple comments:

- It is customary to place asterisks around special variables in order
  to minimise the potential for accidents:

  (defvar *one* 1)

- It's generally considered a very bad idea to compare numbers with
  EQ.  In some implementations, (eq 1 1) may return false!  Use EQL
  instead.  (But note that (eql 1 1.0) is false.  Use EQUALP if you
  want true in this situation, or = if you know that both arguments
  will be numbers.)

- Finally, IF (NOT ...) can be written UNLESS ...

;;; TEST:
(defvar *one* 1)
*ONE*
;;; TEST:
(loop for item in '(1 2 3)
      unless (eql item *one*)
      collect item into list-result
      finally (return list-result))
(2 3)

I hope this helps.

(I won't even mention that (delete 1 '(1 2 3)) does the same job.)

- Harald

Reply via email to