Re: legitimate closure?



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.


.



Relevant Pages

  • Re: closures and dynamic binding
    ... The double lambda is conceptually more sound in some ... I agree that the default argument syntax is an abuse, ... don't think there's a way to create a closure in Python without ... overrides the outer scope. ...
    (comp.lang.python)
  • Re: Lisp in hardware
    ... > pre-computed index into an environment. ... You have to "pre-compute" a LAMBDA just as much (or rather, ... because the closure object has to hold the captured lexical ...
    (comp.lang.lisp)
  • Re: Cost of closures
    ... a closure consists of a piece of code and a set of lexical ... by the same lambda while the environment part is different. ... in a register or on the stack. ... it must indirect through the `this' pointer. ...
    (comp.lang.lisp)
  • Re: I thought this was the one that worked?
    ... It's still a closure. ... closure for a block regardless. ... That lambda still has a reference to ...
    (comp.lang.ruby)
  • Re: Anonymous methods, blocks etc. (Cont. default block params)
    ... What does "closure capabilities" mean ... >> so far suggested for anonymous functions. ... > for def style semantics (i.e. 'true' anonymous function, opaque scope, ... in a lambda, it will return from the lambda only. ...
    (comp.lang.ruby)