Re: Prefer CLOS over closures that modify variables they close over?



Pillsy <pillsbury@xxxxxxxxx> writes:

On May 24, 1:30 pm, "ricky.clark...@xxxxxxxxx"
<ricky.clark...@xxxxxxxxx> wrote:
It appears that I've misrepresented the channel here, so you may
disregard the above in terms of how it paints #lisp, but I'm still
interested to see why and when various people would use CLOS over a
closure.

If it were something that simple, I'd probably just make it a closure.
I haven't really thought about why too much, beyond the fact that it
feels like the most natural abstraction to use. You call a function,
you get the number of times it's been called, and it's all very
simple.

Actually, if it were that simple, I expect most Lispers would write

(let ((x 0))
(incf x (<function call>)))

rather than passing a closure as an argument to modify x. I assume
the real scenario is more complicated, of course.
.



Relevant Pages

  • Re: A question (confusion) about closure
    ... If you could, put out a snippet of code of closure, in emacs lisp. ... I'll show how it is done with global vars. ... Common Lisp is fine but i don't know Common Lisp. ...
    (comp.lang.lisp)
  • Re: A question (confusion) about closure
    ... If you could, put out a snippet of code of closure, in emacs lisp. ... I'll show how it is done with global vars. ... Common Lisp is fine but i don't know Common Lisp. ...
    (comp.lang.lisp)
  • Re: Performance of CLOS over closures
    ... I could be implementing the same code that is in CLOS ... each time I put together a closure. ... Tune your code only as soon as you know that you have a bottleneck, and then only worry about that bottleneck. ... 1st European Lisp Symposium ...
    (comp.lang.lisp)
  • Re: Closures in Java (and Lisp, sort of)
    ... > which anonymous inner classes seem appropriate. ... > public class IckyClosure { ... and it struck me that I've re-invented the closure. ... > actual Lisp closures (aside from Lisp figuring out what variables to ...
    (comp.lang.lisp)
  • Re: closure vs global
    ... I think it can be done in better ways than global..i don't know if in lisp it's the same/. ... i was wondering if there was a way using lexical variable, to write a closure so i could get rid of the global and still refer to the variable from those functions where i had *test* as global. ... ...code that process game bound to local variable...) ... or are is *test* where you want to put some-lambda? ...
    (comp.lang.lisp)