Re: legitimate closure?



In article
<82bfc8fb-154e-47d2-b3ab-c50d6a2c904a@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Mirko.Vukovic@xxxxxxxxx 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/
.



Relevant Pages

  • Re: Purpose of the LAMBDA keyword?
    ... lambda calculus A as the implementation language. ... Turing Machines, they're Von Neuman Machines, or Universal Turing ... the Univeral Lambda Function doesn't access its own ...
    (comp.lang.scheme)
  • Re: Lexical scope question
    ... ; because of this DECLARE ... binding of var correctly ... It's not a lambda function. ...
    (comp.lang.lisp)
  • Re: question re let and lambda syntax
    ... presented problem f is bound to the lambda function (lambda ... And it is here that I get lost - the lambda function. ... No insult to Scheme intended. ... | this function, and they are assigned to the formals x, y, ...
    (comp.lang.scheme)
  • Re: question re let and lambda syntax
    ... And it is here that I get lost - the lambda function. ... understanding of Scheme. ... This is the definition of that particular form of "lambda". ...
    (comp.lang.scheme)
  • Re: A question about unicode() function
    ... funUrlFetch = lambda url:urllib.urlopen.read ... UnicodeDecodeError: 'ascii' codec can't decode byte 0xbb in position ... lambda url:urllib.urlopen.readThis function only creates a lambda function (that is not used or ...
    (comp.lang.python)