Re: "Staggering power of closures..."
From: Dave Roberts (ldave-re-move_at_re-move.droberts.com)
Date: 03/29/04
- Next message: Dave Roberts: "Re: "Staggering power of closures...""
- Previous message: Tayssir John Gabbour: "Re: Flaw in Conditions System?"
- In reply to: Peter Seibel: "Re: "Staggering power of closures...""
- Next in thread: Boris Schaefer: "Re: "Staggering power of closures...""
- Reply: Boris Schaefer: "Re: "Staggering power of closures...""
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 29 Mar 2004 01:44:46 GMT
Peter Seibel wrote:
> The difference is mostly one of convenience. When I write:
>
> (defun foo (x y z things)
> (mapcar #'(lambda (thing) (frob x y thing)) things))
>
> I don't have to think about making a class to hold the X and Y values.
> And when I decide I want to change that to:
>
> (defun foo (x y z things)
> (mapcar #'(lambda (thing) (super-frob x y z thing)) things))
>
> I don't have to also go edit my class definition to add a field to
> hold the Z value. Inner classes, give this part of the convenience of
> closures since the compiler figures out which local variables I'm
> refering to and creates a class with just the right fields to hold
> them and under the covers calls a constructor with the local variables
> as arguments so their values can be used to initialize the fields.
Right, good point. So this is pretty nice. "Low overhead" is I guess the way
I would put it.
> The difference of course, as various folks have pointed out, is that
> the instance of the inner class has a copy of the *value* not a
> reference to the actual variable, so it's trickier to write the
> equivalent of this:
>
> (defun foo (things)
> (let ((count 0))
> (values (mapcar #'(lambda (thing)
> (when (good-p thing) (incf count))
> (frob thing)) things)
> count)))
>
> (The nearest translation in Java would involve making count a mutable
> object such as a one-element array. Which is pretty gross and liable
> to confuse the heck out of your average Java programmer.)
Yup. The syntax is just so much cleaner in general. I fully agree with that.
As you say, you could do it in Java, but the amount of pain goes up
substantially, which sort of steers you away from using. With Lisp, it's a
lot easier and so you're more likely to use it.
-- Dave Roberts ldave-re-move@re-move.droberts.com
- Next message: Dave Roberts: "Re: "Staggering power of closures...""
- Previous message: Tayssir John Gabbour: "Re: Flaw in Conditions System?"
- In reply to: Peter Seibel: "Re: "Staggering power of closures...""
- Next in thread: Boris Schaefer: "Re: "Staggering power of closures...""
- Reply: Boris Schaefer: "Re: "Staggering power of closures...""
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|