Re: Discussion: Closures

Patrick Niemeyer <[email protected]> Thu, 3 Feb 2005 13:51:11 -0600
Newsgroups gmane.comp.java.beanshell.devel
Message-ID <[email protected]>
On Feb 3, 2005, at 11:53 AM, Shankar Unni wrote:

> The only minor quibble I might have is for the parameter declaration 
> syntax.
> Does this not look more natural?:
>
>   x = callable() {
>      foo = someMethod();
>      bar++;
>   };
>
>   z = callable(foo, bar) {
>      print(foo);
>      someMethod(bar);
>   };
>
>   x.call();
>   z.call(foo,bar);

Thanks for bringing this up. To generalize a little, I think this 
raises the question of how we could use the Java anonymous inner class 
syntax extended to BeanShell scripted objects.

Suppose you have a bsh method closure foo:

foo() {
	x=42;
    // return this;
}

What if you could extend that definition using the familiar Java anon 
inner class syntax:

bar=foo() { y=43; };


This would extend the scripted foo object anonymously.  To be 
applicable to the closure problem we'd need a form that delayed 
evaluation...  and took arguments creatively...


Pat




-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl