Like Neal said, it's a Turing machine. Everything atop of LISP is sugar. The
point is closing over the *binding* not the value. Otherwise it's simply an
implied invocation parameter.

2009/11/30 Alexey Zinger <inline_f...@yahoo.com>

> Josh,
>
> Let's not forget that we can do these things in Java now, even without any
> kind of closure syntax sugar.  If syntax makes it easier, so much the
> better.
>
> public interface Closure<P, R> { public R call(P param); }
>
> // stuff happened...
>
> public Closure<Integer, Integer> showClosure()
> {
>   final int[] localVar = new int[] { 9 };
>   Closure<Integer, Integer> f = new Closure<Integer, Integer>()
>   {
>     public Integer call(int x)
>     {
>       int result = localVar[0] + x;
>       localVar[0] = 10;
>       return result;
>   };
>   return f;
> }
> localVar[0] = 9;
>
> // more stuff happened...
>
> Closure<Integer, Integer> cl = showClosure();
> System.out.println(cl.call(1));
> System.out.println(cl.call(2));
>
> Alexey
> http://azinger.blogspot.com
> http://bsheet.sourceforge.net
> http://wcollage.sourceforge.net
>
>
> ------------------------------
> *From:* Josh McDonald <j...@joshmcdonald.info>
> *To:* javaposse@googlegroups.com
> *Sent:* Sun, November 29, 2009 8:44:14 PM
> *Subject:* Re: [The Java Posse] Re: Closures, too much or too little?
>
> Let me have a crack at it. Here's some Javascript code:
>
> function showClosure()
> {
>     var localVar = 7;
>     var f = function(x)
>         {
>             var result = x + localVar;
>             localVar = 10;
>             return result;
>         }
>     localVar = 9;
>     return f;
> }
>
> var cl = showClosure();
> print(cl(1)); // <-- 10
> print(cl(2)); // <-- 12
>
> Without real closures, you'll get something else other than 10 and 12,
> depending on where the limitations are in the bindings. You may get 8 and 9
> (I /think/ this is what Obj-C blocks will do), or you may get 10 and 11.
>
> With real closures, the local variables like localVar need to go on the
> heap for garbage collection instead of on the stack, which is a fairly
> signifigant change, which I beleive is why LambdaJ can't do it.
>
> Disclaimer: Just because I (think I) understand it, doesn't mean I can
> necessarily explain it :-/
>
> -Josh
>
> 2009/11/26 Joe Nuxoll (Java Posse) <jnux...@gmail.com>
>
>> Gotta say it...  This is not far off from the events part of this
>> proposal from 2004:
>> http://blogs.sun.com/joe/resource/java-properties-events.pdf
>>
>> I just had slightly little different syntax:
>>
>>
>> -------------------------------------------------------------------------8<
>> // using an event keyword – method declaration same
>> // as everywhere else in Java (nice – my favorite)
>> public event boolean onMouseClicked(JButton button, Point clickPoint,
>> int clickCount);
>>
>> // maybe specify if its multicast?
>> // or should they all just be considered multicast?
>> public multicast event boolean onMouseClicked(JButton button, Point
>> clickPoint, int clickCount);
>>
>> // or a new [] syntax to mean “method pointer”
>> // note that param names are included for IDE code-
>> // insight information – this is more like a field declaration
>> public [boolean: JButton button, Point clickPoint, int clickCount]
>> onMouseClicked;
>>
>> // a no-arg, void return method pointer
>> // (syntax looks silly?)
>> public [void:] somethingHappened;
>>
>> // looks a little better using an event keyword
>> public event void somethingHappened();
>> public [Object: int feet, int inches] onJump throws VaultException;
>>
>> // read-only (final) 'mouseEvents' field
>> public final MouseEvents mouseEvents = new MouseEvents();
>>
>> // read-only 'mouseEvents' property (same thing)
>> public MouseEvents mouseEvents get = new MouseEvents();
>>
>> -------------------------------------------------------------------------8<
>>
>>  - Joe
>>
>> On Nov 18, 2:13 pm, mikaelgrev <mikael.g...@gmail.com> wrote:
>> > ...or too late (but not really since pre Java 7 was never an option)?
>> >
>> > I think the complexity of these proposed Closures are just right for
>> > Java. Not so for Rock Start Programmers, but for 90% of us.
>> >
>> > Syntax takes getting used to, but that's not biggie.
>> >
>> > Less pitfalls than BGGA, that's what makes me happy. BGGA are perfect
>> > for 10% of those 5 000 000 Java developers but really bad for, say,
>> > 30% since they'd had to re-learn more than they would've been able to
>> > handle or want to.
>> >
>> > Unless you haven't seen the spec:
>> http://www.javac.info/closures-v06a.html
>> >
>> > What you guys think?
>> >
>> > Cheers,
>> > Mikael
>>
>> --
>>
>> You received this message because you are subscribed to the Google Groups
>> "The Java Posse" group.
>> To post to this group, send email to javapo...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> javaposse+unsubscr...@googlegroups.com<javaposse%2bunsubscr...@googlegroups.com>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/javaposse?hl=en.
>>
>>
>>
>
>
> --
> "Therefore, send not to know For whom the bell tolls. It tolls for thee."
>
> Josh 'G-Funk' McDonald
>   -  j...@joshmcdonald.info
>   -  http://twitter.com/sophistifunk
>   -  http://flex.joshmcdonald.info/
>
>  --
> You received this message because you are subscribed to the Google Groups
> "The Java Posse" group.
> To post to this group, send email to javapo...@googlegroups.com.
> To unsubscribe from this group, send email to
> javaposse+unsubscr...@googlegroups.com<javaposse%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/javaposse?hl=en.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "The Java Posse" group.
> To post to this group, send email to javapo...@googlegroups.com.
> To unsubscribe from this group, send email to
> javaposse+unsubscr...@googlegroups.com<javaposse%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/javaposse?hl=en.
>



-- 
"Therefore, send not to know For whom the bell tolls. It tolls for thee."

Josh 'G-Funk' McDonald
  -  j...@joshmcdonald.info
  -  http://twitter.com/sophistifunk
  -  http://flex.joshmcdonald.info/

--

You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to javapo...@googlegroups.com.
To unsubscribe from this group, send email to 
javaposse+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.


Reply via email to