RE: Discussion: Closures
"Yemi D. Bedu" <yemi-DnQzskBZRmpWk0Htik3J/[email protected]> Thu, 3 Feb 2005 12:03:11 -0500
| Newsgroups | gmane.comp.java.beanshell.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello,
I don't think that for the appeal of being able to do what, having
callable(...) instead of {} would keep me from using it. We then may
fuss about for(...;...;...){...} to be (...;...;...;{...}) (last element
a closure) for more (sweet-brown) sugar code. But then you can just
define an internal syntax as a plugin script and get this the way you
like. I don't care to have a verbose syntax for some things if I can
easily dive into and re-define their syntactic readability with my
plug-in. That is nice power I like on my side. If fact would like to
work through the entire(or 99%) of the language like this.
One things, would this be like a template system. So would I be able to
design a plug-in like:
S-Define-Plug:
(%a%; %b%; %c%;{%d%})
From:
for(%a%; %b%; %c%){%d%}
E-Define-Plug:
-----Original Message-----
From: beanshell-developers-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
[mailto:beanshell-developers-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org] On Behalf Of
Patrick Niemeyer
Sent: Thursday, February 03, 2005 11:32 AM
To: BeanShell Developers
Cc: Bob Lee
Subject: [Beanshell-dev] Discussion: Closures
One thing that people often ask about is closures. Technically
BeanShell namespaces and method closures have always let you do more or
less arbitrary things, but there is no convenience syntax for using
these features.
One possibility would be to use another eval-like method. For example,
it could be named callable(). It could return a closure with a call()
method, and the whole thing might map to the Java type
java.util.concurrent.Callable where appropriate. This would primarily
be a delayed evaluation form of eval() that could take additional
leading arguments, etc.
x = callable( foo=someMethod(); print("hello"); );
y = callable(
foo=someMethod();
bar++;
print("hello");
);
z=callable( foo, bar,
print(foo);
someMethod(bar)
);
x.call();
y.call();
z.call( "foo", "bar" );
The alternative (as discussed) would be to use the more concise { }
block-like syntax that we've discussed before. My only fear there is
that it could become ambiguous with Java syntax.
For example:
c={ someMethod(); }
Is that a closure or is it just a loose form of:
Object [] c = { someMethod() };
Technically the semi-colon makes it a statement and we can
differentiate the two. But from a human standpoint it is a little hard
to tell at first whether this is some kind of array/list syntax or a
closure.
Maybe the { } syntax is useful enough to warrant it. Is the appeal of
closure delicate enough that it's lost by having to type a few extra
characters? ;) Maybe so.
Please send feedback.
thanks,
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
_______________________________________________
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: 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