Expression closures - use-cases for shortcut lambda syntax (blocks)

Vassily Gavrilyak gavrilyak at gmail.com
Sat Mar 17 12:46:00 PDT 2007


> addLoadEvent(function(){
>      connect('bad_example','onclick', \(e) signal('bad_example'));
>      connect('bad_example','showvalue',window,'alert');
>
>      connect('good_example','onclick', \(e) signal(randomObj));
>      connect(randomObj,'showvalue',window,'alert');
> });
>

Actually it should be this, with operator, functions expressions,
types and lambda

addLoadEvent(function(){
   bad_example.onclick   += (\ _)  bad_example.showvalue("explicit_value");
   bad_example.showvalue += (\ s:String) window.alert(s);
   good_example.onclick  += (\ _)  randomObj.showvalue("explicit_value");
   randomObj.showvalue   += (\ s:String) window.alert(s);
});

Now it's cleared from all the syntactic noise.
Signal-slot framework in ES is something strange that should not be here at all.
ES object properties are slots and functions calls are signals.
Connection should be an assignment. ES is not C++, there is no needs
for workarounds
Thats the first thing bad with this example.
Second thing is that is uses method names in order to actually shorten
up code (avoid writing 'function' directly).
With operators, expression closures and lambdas there will be no place
left for such framework. Everything would be possible to write
directly and use typing and compilation niceties.

Vassily.



More information about the Es4-discuss mailing list