m.invoke() vs. m()

Vladimir Kirichenko vladimir.kirichenko at gmail.com
Sat Dec 5 11:31:06 PST 2009

Reinier Zwitserloot wrote:
> Solution:
> c.invoke(args) is the only legal closure invocation syntax. c(args)
> isn't. 

You're saying all the languages dealing with closures without any kind
of "invoke" made by aliens?

> Is 'invoke' some serious curseword in programmese? Does it offend
> you so that this syntax just cannot stand?

Yes it is. Why don't we use this syntax to invoke regular methods? It is
a _function call_.

One of the problems in todays java community I see is that lots of
efforts wasted on reinventing the wheel or thinking that problems
discovered have not been faced by others. Those are not new. Lambda is
not something new. There are dozens of languages with lambdas or/and
function types. There are syntax examples, the ways to deal with the
problems you're describing. There is nothing new. Java is a follower in
this case not a leader.

For your example it's just enough to look at twin brother - C#:

public class Test {
        public delegate void unit();
        public unit x = () => Console.println(1);
        public void x() {Console.println(2);}

./mcs -langversion:Future Test.cs
Test.cs(5,21): error CS0102: The type `Test' already contains a
definition for `x'
Test.cs(4,21): (Location of the symbol related to previous error)
Compilation failed: 1 error(s), 0 warnings

Similar language, same problems - not an issue. Invocation syntax: x();


scala> class Test {
     | val x = println(1)
     | def x() = println(2)
     | }
<console>:6: error: value x is defined twice
       def x = println(2)

Not a problem. Invocation syntax: x();


#include <iostream>

using namespace std;

class Test {
        void x() { cout << 1; }
        void (*x)();

g++ Test.cpp
Test.cpp:7: error: declaration of ‘void (* Test::x)()’
Test.cpp:6: error: conflicts with previous declaration ‘void Test::x()’

Nothing new. Invocation syntax: x();

Best Regards,
Vladimir Kirichenko

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 259 bytes
Desc: OpenPGP digital signature
Url : http://mail.openjdk.java.net/pipermail/closures-dev/attachments/20091205/e95f1aa9/attachment-0001.bin 

More information about the closures-dev mailing list