Re: Closures

Bob Lee <[email protected]>
Newsgroups gmane.comp.java.beanshell.devel
Message-ID <[email protected]>
I use BeanShell for the configuration in dynaop which means you can 
implement custom pointcuts, factories, and initializers right in the 
bsh script. All three of these are essentially command objects that 
accept an argument. For example, without closures, it looks something 
like this:

interceptor(
   new ClassPointcut() {
     picks(clazz) {
       return clazz.name.equals(...);
     }
   },
   new MethodPointcut() {
     picks(method) {
       return method.name.equals(...);
     }
   },
   new InterceptorFactory() {
     create(proxy) {
       return ...;
     }
   },
);

With closures, I could do something more like this ('it' is an implicit 
argument in this example, the syntax you settle on doesn't matter to me 
much):

interceptor(
   { return it.name.equals(...); },
   { return it.name.equals(...); },
   { return ...; },
};

I was skeptical about closures at first as well, but after using Ruby 
(which I don't like overall), I've actually started to use command 
objects like this more and more in my Java development, and I do see 
the value in them. I've also always liked anonymous functions in 
Javascript which are pretty much the same thing--they work great for 
callbacks, etc.

Thanks,
Bob

On Apr 24, 2004, at 11:24 AM, Curt Cox wrote:

> Bob,
>
> Closures mean different things to different people.
> The more concrete details and use cases you could supply,
> the better.
>
> If there is a reasonable way to structure BeanShell so that
> there is a core language along with different (often incompatible)
> language extensions, then that might be worthwhile.
> That is the only way that I can see to possibly accomodate
> all of the syntax extensions that people want.
>
> So, what do you mean when you say "closures"?
>
> Thanks,
> Curt
>
> Bob Lee wrote:
>
>> Please, please, please add support for closures. They would save on a 
>> lot of typing and would make the dynaop configuration a lot more 
>> extendable and readable.
>>
>> Thanks,
>> Bob
>>
>>
>>
>> -------------------------------------------------------
>> This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek
>> For a limited time only, get FREE Ground shipping on all orders of $35
>> or more. Hurry up and shop folks, this offer expires April 30th!
>> http://www.thinkgeek.com/freeshipping/?cpg=12297
>> _______________________________________________
>> Beanshell-developers mailing list
>> Beanshell-developers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
>> https://lists.sourceforge.net/lists/listinfo/beanshell-developers
>
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek
> For a limited time only, get FREE Ground shipping on all orders of $35
> or more. Hurry up and shop folks, this offer expires April 30th!
> http://www.thinkgeek.com/freeshipping/?cpg=12297
> _______________________________________________
> Beanshell-developers mailing list
> Beanshell-developers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/beanshell-developers



-------------------------------------------------------
This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek
For a limited time only, get FREE Ground shipping on all orders of $35
or more. Hurry up and shop folks, this offer expires April 30th!
http://www.thinkgeek.com/freeshipping/?cpg=12297
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.