In mobl you have Callback {} with the only input I think “event” like this:

var cb : Callback = {
alert(event);
};

cb(“simple test”);

In languages like Ruby you have also named parameters like:

{ |a,b| print a,b }

Is it planned something more like this in mobl? Or is it possible to set other variables than “event”?

Submitted by Terje Pedersen on 28 April 2011 at 09:57

On 28 April 2011 at 10:06 Zef Hemel commented:

This is indeed planned: https://yellowgrass.org/issue/mobl/70. Any feedback on syntax is welcome, however I would prefer to keep it close to Javascript.


On 28 April 2011 at 10:39 Terje Pedersen commented:

Good question about syntax, I think I need to think about it :)


javascript:
function(a,b) {code}

ruby:
{|a,b| code}

groovy:
{a,b -> code}

python:
lambda a,b: code


On 5 May 2011 at 08:36 Terje Pedersen commented:

Some examples of how it could look like.

function(a:Num, b:String) {code}
{|a:Num, b:String| code}
{a:Num,b:String -> code}
{a:Num,b:String => code}
{a:Num,b:String :: code}

Test example:

var ar = [1, 2, 3, 4];
ar.filter({n : Num, Bool -> return n % 2 == 0; });


On 13 May 2011 at 13:32 Zef Hemel commented:

Implemented this both for anonymous controls and functions in 0.4.4. Syntax:

var fn = function(a : Num) : Num { return a + 10; };
var ctrl = control(a : Num) { label(a + 10) };

On 13 May 2011 at 13:32 Zef Hemel tagged 0.4.4

On 13 May 2011 at 13:32 Zef Hemel closed this issue.

On 17 June 2011 at 08:25 Terje Pedersen commented:

This is working:

function xy(it : Num) : [Num] {
return [it, 2000];
}

function accountgroup() : [Num] {
var r = range(0,13);
return [r.map(xy)];
}

But with the new anonymous function I get errors:

function accountgroup() : [Num] {
var r = range(0,13);
var xy = function(it : Num) : [Num] { return [it, 2000]; };
return [r.map(xy)];
}

And while typing I know why, the compiler thinks the return inside the anonymous function is the return of accountgroup()

Log in to post comments