Syntax...
Jakob Praher
jp at hapra.at
Sat Nov 21 07:11:33 PST 2009
Sorry for the noise again,
another important point is that I would not separate expressions form
statements. This something which should be adressed by the Java language
on a larger scale.
Too many different ways are not consistent and introduce headaches for
people experienced with Java w/o closures.
E.g.
Why can I write
f.listFiles( #(File pathname) pathname.getName().endswith(".txt") )
while not
public static bool accept(File pathname) pathname.getName().endswith(".txt")
IMHO it is much more important to beeing able to write something like:
f.listFiles(File patname) {
return pathname.getName().endswith("txt");
}
I would stick with return for the current change and address the
statement/expression dichotomy on a larger picture.
Also what one sees with "pathname.getName().endswith(...)" above is that
extreme consiceness is not the main goal of Java while consistency I
think is(One way to do things).
So my point: In the end a closure/lambda/method should be consistent
representation of executable code.
-- Jakob
Jakob Praher schrieb:
> Hi all,
>
> why do we need something like #, ^ for defining the function type at all?
>
> IMHO in Java the identifier space has no function type already, since
> this is a novelity, compared with C/C++ block/lambda concepts build on
> top of existing function pointers. This implies the opportunity to
> introduce a clean function/lambda type identifier, which would also
> leverage a common representation.
>
> I would not introduce new operators like => or # if it is not
> absolutely necessary. Java style would be to use something more
> readable IMHO.
> Introducing closures with new would have the charme of beeing similar
> to anonymous inner class instantiation.
>
> e.g.
>
> File f = new File(".");
> File[] textfiles = f.listFiles( new FileFilter() {
> public boolean accept(File pathname) {
> return pathname.endswith(".txt");
> });
>
> which would be translated to:
>
> File f = new FIle(".");
> File[] textfiles = f.listFiles( new (File pathname) {
> pathname.endswith("txt") } );
>
> "new" is surely debatable and one could think about omitting it....
> Then one could also think about more scala like:
>
> f.listFiles (File pathanme) {
> return pathname.endswith("txt") ;
> }
>
> If the only argument to a method is a closure, one could leave out the
> parenthesis and it looks much more readable IMHO.
> Surely this would be a bigger burdon to the compiler, but even with
> the parenthesis around it would be readable, no?
>
> f.listFiles( (File pathanme) {
> return pathname.endswith("txt") ;
> });
>
> Just my 2 cents.
> -- Jakob
>
> tronicek at fit.cvut.cz schrieb:
>> Hi,
>>
>> I do not have any strong argument neither for # nor for ^ but I,
>> personally, prefer # (for both, function types and lambdas). Why?
>> ^ is an operator and thus # seems to be more readable.
>> In C, the situation is different: # is a preprocessor thing and so ^ is
>> probably better there.
>>
>> Zdenek
>>
>
>
More information about the closures-dev
mailing list