Re: legitimate closure?
- From: pjb@xxxxxxxxxxxxxxxxx (Pascal J. Bourguignon)
- Date: Sat, 30 Aug 2008 23:25:17 +0200
Mirko.Vukovic@xxxxxxxxx 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.
.
- References:
- legitimate closure?
- From: Mirko . Vukovic
- legitimate closure?
- Prev by Date: Re: legitimate closure?
- Next by Date: Re: legitimate closure?
- Previous by thread: Re: legitimate closure?
- Next by thread: Re: legitimate closure?
- Index(es):
Relevant Pages
|