This closure works on clisp on cygwin+windows:
cl-user> (let ((list (list 1 2 3 4 5))
(item 4))
(delete item list :test #'(lambda (unused b) (= item b))))
(1 2 3 5)
I used closure for lambda to get "item" from delete's first argument
The straightforward version is
cl-user> (let ((list (list 1 2 3 4 5))
(item 4))
(delete item list :test #'(lambda (a b) (= a b))))
I'm not sure why would this ever be useful, but I was surprised that
lambda captured it.
Mirko
In article
<····································@26g2000hsk.googlegroups.com>,
·············@gmail.com wrote:
> This closure works on clisp on cygwin+windows:
> cl-user> (let ((list (list 1 2 3 4 5))
> (item 4))
> (delete item list :test #'(lambda (unused b) (= item b))))
> (1 2 3 5)
>
> I used closure for lambda to get "item" from delete's first argument
Not sure what you are saying, but the ITEM in the LAMBDA form
refers to the ITEM introduced by the LET. That's fine.
The ITEM as a argument to DELETE is also referring to
the ITEM introduced by the LET. That's fine, too.
UNUSED has in every call of the LAMBDA function
the value of ITEM. So ITEM and UNUSED have the same value.
>
> The straightforward version is
> cl-user> (let ((list (list 1 2 3 4 5))
> (item 4))
> (delete item list :test #'(lambda (a b) (= a b))))
>
> I'm not sure why would this ever be useful, but I was surprised that
> lambda captured it.
I thought that the most straightforward way would call DELETE like
this:
(delete item list)
or
(delete item list :test #'=) if you want to call the
= function.
:test (lambda (a b) (= a b)) is the more complicated version of
:test #'=
>
> Mirko
--
http://lispm.dyndns.org/
·············@gmail.com writes:
> This closure works on clisp on cygwin+windows:
> cl-user> (let ((list (list 1 2 3 4 5))
> (item 4))
> (delete item list :test #'(lambda (unused b) (= item b))))
> (1 2 3 5)
>
> I used closure for lambda to get "item" from delete's first argument
Why? DELETE already pass it to your TEST function, in the UNUSED
parameter, since you gave ITEM to DELETE.
> The straightforward version is
> cl-user> (let ((list (list 1 2 3 4 5))
> (item 4))
> (delete item list :test #'(lambda (a b) (= a b))))
>
> I'm not sure why would this ever be useful, but I was surprised that
> lambda captured it.
It did not. You passed explicitely ITEM to DELETE, and DELETE passes
it explicitely to your TEST function.
C/USER[6]> (let* ((list (list (cons 1 1) (cons 2 2) (cons 3 3) (cons 4 4) (cons 5 5)))
(item (fourth list)))
(delete item list :test (lambda (a b)
(print `(is a identical to item? --> ,(eq a item)))
(print (member b list))
(eq a b))))
(IS A IDENTICAL TO ITEM? --> T)
((1 . 1) (2 . 2) (3 . 3) (4 . 4) (5 . 5))
(IS A IDENTICAL TO ITEM? --> T)
((2 . 2) (3 . 3) (4 . 4) (5 . 5))
(IS A IDENTICAL TO ITEM? --> T)
((3 . 3) (4 . 4) (5 . 5))
(IS A IDENTICAL TO ITEM? --> T)
((4 . 4) (5 . 5))
(IS A IDENTICAL TO ITEM? --> T)
((5 . 5))
((1 . 1) (2 . 2) (3 . 3) (5 . 5))
--
__Pascal Bourguignon__ http://www.informatimago.com/
PLEASE NOTE: Some quantum physics theories suggest that when the
consumer is not directly observing this product, it may cease to
exist or will exist only in a vague and undetermined state.
MV> This closure works on clisp on cygwin+windows:
MV> cl-user> (let ((list (list 1 2 3 4 5))
MV> (item 4))
MV> (delete item list :test #'(lambda (unused b) (= item b))))
MV> (1 2 3 5)
MV> I used closure for lambda to get "item" from delete's first argument
your broken comparison function has no relation whatsoever to delete's
first argument. try this:
(let ((list (list 1 2 3 4 5))
(item 4))
(delete 777 list :test #'(lambda (unused b) (= item b))))
(1 2 3 5)
if you do not use "item" parameter, use delete-if instead of delete:
(let ((list (list 1 2 3 4 5))
(item 4))
(delete-if (lambda (unused b) (= item b)) list))
MV> I'm not sure why would this ever be useful, but I was surprised that
MV> lambda captured it.
the only thing lambda capture are lexical variables, introduced by LET,
function parameters and stuff like this.