Suggestion: Lambda Expressions like a => a > 0 as haxe imprevement

classic Classic list List threaded Threaded
33 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Suggestion: Lambda Expressions like a => a > 0 as haxe imprevement

Heinz Hölzer-2
I would really like to see Lambda Expressions (or a shorter syntax for
them) in haxe.

I found the discussion about that in the topic "[haXe] Would "var"
keyword be considered an example of imperative", and i would like
to hear what the community think about that.

The concept is really simple, it would be just another way to write
anonymous functions.

instead of

function (a) { return "something"; } or function (a) return "something"

you can write

a => "something"

or with more than one parameter

(a,b) => a + b

or with a block

(a,b) = {
    if (a < b) return -1;
    if (a > b) return 1;
    return 0;
}

Together with the using syntax and The Lambda class you can write nice
and clean code:

using Lambda;

var a = new List<Int>();

a.filter( a => a > 1 )

instead of

a.filter( function (a) return a > 1)

or more advanced

a.filter

which i think is much more expressive and you can focus more on the what
than the how, especially when you combine expressions.
The syntax style is from C# and there are more C# examples on the web:

http://blogs.msdn.com/ericwhite/pages/Lambda-Expressions.aspx
http://blah.winsmarts.com/2006/05/19/demystifying-c-30--part-4-lambda-expressions.aspx
http://www.codeproject.com/KB/cs/explore_lamda_exp.aspx


what do you think about that? Would it be a good Idea to implement this
Syntax in haxe?

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion: Lambda Expressions like a => a > 0 as haxe imprevement

Simon Krajewski
Heinz Hölzer schrieb:
> what do you think about that? Would it be a good Idea to implement
> this Syntax in haxe?
I like this a lot, even though it reminds me of Haskell. It might be
tricky to parse though.

(a,b) => a + b
c = 5;

You cannot tell where the function body ends unless you consider the
newline, which the parser doesn't do as far as I know (correct me if I'm
wrong). Adding a ; might cause trouble for constructs like filter( a =>
a > 1; );

If this can be solved (mandatory blocks?), I'd love to see this in haXe.
I hate writing closures at the moment, so this would be a great
alternative. What about nested  anonymous functions?

Regards
Simon



--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion: Lambda Expressions like a => a > 0 as haxe imprevement

Armén
In reply to this post by Heinz Hölzer-2
Is this purely syntactical construct? I mean, compiler would do
exactly what it does with closures?

When I wrote that topic on "var", I meant to express a need for
"aliases", i.e. compiler assisted aliases for expressions, like "alias
g = obj.graphics;"

2009/8/12 Heinz Hölzer <[hidden email]>:

> I would really like to see Lambda Expressions (or a shorter syntax for them)
> in haxe.
>
> I found the discussion about that in the topic "[haXe] Would "var" keyword
> be considered an example of imperative", and i would like
> to hear what the community think about that.
>
> The concept is really simple, it would be just another way to write
> anonymous functions.
>
> instead of
>
> function (a) { return "something"; } or function (a) return "something"
>
> you can write
>
> a => "something"
>
> or with more than one parameter
>
> (a,b) => a + b
>
> or with a block
>
> (a,b) = {
>   if (a < b) return -1;
>   if (a > b) return 1;
>   return 0;
> }
>
> Together with the using syntax and The Lambda class you can write nice and
> clean code:
>
> using Lambda;
>
> var a = new List<Int>();
>
> a.filter( a => a > 1 )
>
> instead of
>
> a.filter( function (a) return a > 1)
>
> or more advanced
>
> a.filter
>
> which i think is much more expressive and you can focus more on the what
> than the how, especially when you combine expressions.
> The syntax style is from C# and there are more C# examples on the web:
>
> http://blogs.msdn.com/ericwhite/pages/Lambda-Expressions.aspx
> http://blah.winsmarts.com/2006/05/19/demystifying-c-30--part-4-lambda-expressions.aspx
> http://www.codeproject.com/KB/cs/explore_lamda_exp.aspx
>
>
> what do you think about that? Would it be a good Idea to implement this
> Syntax in haxe?
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion: Lambda Expressions like a => a > 0 as haxe imprevement

Heinz Hölzer-2
In reply to this post by Heinz Hölzer-2
And you can also create nice and short async blocks like

obj.onRelease = event => {
    doSomething(event);
}

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion: Lambda Expressions like a => a > 0 as haxe imprevement

Mark de Bruijn | Dykam
In reply to this post by Simon Krajewski
Simon, it is easily resolved as it is just an expression to be parsed, following the normal rules but with the => having a high priority. Can you give me a case where that would not work?

On Wed, Aug 12, 2009 at 5:15 PM, Simon Krajewski <[hidden email]> wrote:
Heinz Hölzer schrieb:

what do you think about that? Would it be a good Idea to implement this Syntax in haxe?
I like this a lot, even though it reminds me of Haskell. It might be tricky to parse though.

(a,b) => a + b
c = 5;

You cannot tell where the function body ends unless you consider the newline, which the parser doesn't do as far as I know (correct me if I'm wrong). Adding a ; might cause trouble for constructs like filter( a => a > 1; );

If this can be solved (mandatory blocks?), I'd love to see this in haXe. I hate writing closures at the moment, so this would be a great alternative. What about nested  anonymous functions?

Regards
Simon




--
haXe - an open source web programming language
http://haxe.org



--
Mark

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Re: Suggestion: Lambda Expressions like a => a > 0 as haxe imprevement

Mark de Bruijn | Dykam
In reply to this post by Heinz Hölzer-2
Miguel de Icaza proposed +=> for that :p.

@armencho, it is purely syntactical.

2009/8/12 Heinz Hölzer <[hidden email]>
And you can also create nice and short async blocks like

obj.onRelease = event => {
  doSomething(event);
}

--
haXe - an open source web programming language
http://haxe.org



--
Mark

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion: Lambda Expressions like a => a > 0 as haxe imprevement

Heinz Hölzer-2
In reply to this post by Armén
Yes it's just about syntax.

I think there must be an alternative short form for functions, it's
annoying to write "function (a) return a>0" just for a short Boolean
Expression.

[hidden email] schrieb:

> Is this purely syntactical construct? I mean, compiler would do
> exactly what it does with closures?
>
> When I wrote that topic on "var", I meant to express a need for
> "aliases", i.e. compiler assisted aliases for expressions, like "alias
> g = obj.graphics;"
>
> 2009/8/12 Heinz Hölzer <[hidden email]>:
>  
>> I would really like to see Lambda Expressions (or a shorter syntax for them)
>> in haxe.
>>
>> I found the discussion about that in the topic "[haXe] Would "var" keyword
>> be considered an example of imperative", and i would like
>> to hear what the community think about that.
>>
>> The concept is really simple, it would be just another way to write
>> anonymous functions.
>>
>> instead of
>>
>> function (a) { return "something"; } or function (a) return "something"
>>
>> you can write
>>
>> a => "something"
>>
>> or with more than one parameter
>>
>> (a,b) => a + b
>>
>> or with a block
>>
>> (a,b) = {
>>   if (a < b) return -1;
>>   if (a > b) return 1;
>>   return 0;
>> }
>>
>> Together with the using syntax and The Lambda class you can write nice and
>> clean code:
>>
>> using Lambda;
>>
>> var a = new List<Int>();
>>
>> a.filter( a => a > 1 )
>>
>> instead of
>>
>> a.filter( function (a) return a > 1)
>>
>> or more advanced
>>
>> a.filter
>>
>> which i think is much more expressive and you can focus more on the what
>> than the how, especially when you combine expressions.
>> The syntax style is from C# and there are more C# examples on the web:
>>
>> http://blogs.msdn.com/ericwhite/pages/Lambda-Expressions.aspx
>> http://blah.winsmarts.com/2006/05/19/demystifying-c-30--part-4-lambda-expressions.aspx
>> http://www.codeproject.com/KB/cs/explore_lamda_exp.aspx
>>
>>
>> what do you think about that? Would it be a good Idea to implement this
>> Syntax in haxe?
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>>
>>    
>
>  


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion: Lambda Expressions like a => a > 0 as haxe imprevement

Heinz Hölzer-2
In reply to this post by Simon Krajewski
it's already possible to write
filter ( function (a) return a>0);

so this shouldn't be an issue

Simon Krajewski schrieb:

> Heinz Hölzer schrieb:
>> what do you think about that? Would it be a good Idea to implement
>> this Syntax in haxe?
> I like this a lot, even though it reminds me of Haskell. It might be
> tricky to parse though.
>
> (a,b) => a + b
> c = 5;
>
> You cannot tell where the function body ends unless you consider the
> newline, which the parser doesn't do as far as I know (correct me if
> I'm wrong). Adding a ; might cause trouble for constructs like filter(
> a => a > 1; );
>
> If this can be solved (mandatory blocks?), I'd love to see this in
> haXe. I hate writing closures at the moment, so this would be a great
> alternative. What about nested  anonymous functions?
>
> Regards
> Simon
>
>
>


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion: Lambda Expressions like a => a > 0 as haxe imprevement

Armén
In reply to this post by Heinz Hölzer-2
ML uses "->" instead of "=>" and since haXe syntax already uses the
former, perhaps a dash is more appropriate than the "=" ?

2009/8/12 Heinz Hölzer <[hidden email]>:

> Yes it's just about syntax.
>
> I think there must be an alternative short form for functions, it's annoying
> to write "function (a) return a>0" just for a short Boolean
> Expression.
>
> [hidden email] schrieb:
>>
>> Is this purely syntactical construct? I mean, compiler would do
>> exactly what it does with closures?
>>
>> When I wrote that topic on "var", I meant to express a need for
>> "aliases", i.e. compiler assisted aliases for expressions, like "alias
>> g = obj.graphics;"
>>
>> 2009/8/12 Heinz Hölzer <[hidden email]>:
>>
>>>
>>> I would really like to see Lambda Expressions (or a shorter syntax for
>>> them)
>>> in haxe.
>>>
>>> I found the discussion about that in the topic "[haXe] Would "var"
>>> keyword
>>> be considered an example of imperative", and i would like
>>> to hear what the community think about that.
>>>
>>> The concept is really simple, it would be just another way to write
>>> anonymous functions.
>>>
>>> instead of
>>>
>>> function (a) { return "something"; } or function (a) return "something"
>>>
>>> you can write
>>>
>>> a => "something"
>>>
>>> or with more than one parameter
>>>
>>> (a,b) => a + b
>>>
>>> or with a block
>>>
>>> (a,b) = {
>>>  if (a < b) return -1;
>>>  if (a > b) return 1;
>>>  return 0;
>>> }
>>>
>>> Together with the using syntax and The Lambda class you can write nice
>>> and
>>> clean code:
>>>
>>> using Lambda;
>>>
>>> var a = new List<Int>();
>>>
>>> a.filter( a => a > 1 )
>>>
>>> instead of
>>>
>>> a.filter( function (a) return a > 1)
>>>
>>> or more advanced
>>>
>>> a.filter
>>>
>>> which i think is much more expressive and you can focus more on the what
>>> than the how, especially when you combine expressions.
>>> The syntax style is from C# and there are more C# examples on the web:
>>>
>>> http://blogs.msdn.com/ericwhite/pages/Lambda-Expressions.aspx
>>>
>>> http://blah.winsmarts.com/2006/05/19/demystifying-c-30--part-4-lambda-expressions.aspx
>>> http://www.codeproject.com/KB/cs/explore_lamda_exp.aspx
>>>
>>>
>>> what do you think about that? Would it be a good Idea to implement this
>>> Syntax in haxe?
>>>
>>> --
>>> haXe - an open source web programming language
>>> http://haxe.org
>>>
>>>
>>
>>
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion: Lambda Expressions like a => a > 0 as haxe imprevement

Mark de Bruijn | Dykam
That can make processing hard as it confuses between a function typing and function declaration.

On Wed, Aug 12, 2009 at 5:31 PM, [hidden email] <[hidden email]> wrote:
ML uses "->" instead of "=>" and since haXe syntax already uses the
former, perhaps a dash is more appropriate than the "=" ?

2009/8/12 Heinz Hölzer <[hidden email]>:
> Yes it's just about syntax.
>
> I think there must be an alternative short form for functions, it's annoying
> to write "function (a) return a>0" just for a short Boolean
> Expression.
>
> [hidden email] schrieb:
>>
>> Is this purely syntactical construct? I mean, compiler would do
>> exactly what it does with closures?
>>
>> When I wrote that topic on "var", I meant to express a need for
>> "aliases", i.e. compiler assisted aliases for expressions, like "alias
>> g = obj.graphics;"
>>
>> 2009/8/12 Heinz Hölzer <[hidden email]>:
>>
>>>
>>> I would really like to see Lambda Expressions (or a shorter syntax for
>>> them)
>>> in haxe.
>>>
>>> I found the discussion about that in the topic "[haXe] Would "var"
>>> keyword
>>> be considered an example of imperative", and i would like
>>> to hear what the community think about that.
>>>
>>> The concept is really simple, it would be just another way to write
>>> anonymous functions.
>>>
>>> instead of
>>>
>>> function (a) { return "something"; } or function (a) return "something"
>>>
>>> you can write
>>>
>>> a => "something"
>>>
>>> or with more than one parameter
>>>
>>> (a,b) => a + b
>>>
>>> or with a block
>>>
>>> (a,b) = {
>>>  if (a < b) return -1;
>>>  if (a > b) return 1;
>>>  return 0;
>>> }
>>>
>>> Together with the using syntax and The Lambda class you can write nice
>>> and
>>> clean code:
>>>
>>> using Lambda;
>>>
>>> var a = new List<Int>();
>>>
>>> a.filter( a => a > 1 )
>>>
>>> instead of
>>>
>>> a.filter( function (a) return a > 1)
>>>
>>> or more advanced
>>>
>>> a.filter
>>>
>>> which i think is much more expressive and you can focus more on the what
>>> than the how, especially when you combine expressions.
>>> The syntax style is from C# and there are more C# examples on the web:
>>>
>>> http://blogs.msdn.com/ericwhite/pages/Lambda-Expressions.aspx
>>>
>>> http://blah.winsmarts.com/2006/05/19/demystifying-c-30--part-4-lambda-expressions.aspx
>>> http://www.codeproject.com/KB/cs/explore_lamda_exp.aspx
>>>
>>>
>>> what do you think about that? Would it be a good Idea to implement this
>>> Syntax in haxe?
>>>
>>> --
>>> haXe - an open source web programming language
>>> http://haxe.org
>>>
>>>
>>
>>
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org



--
Mark

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion: Lambda Expressions like a => a > 0 as haxe imprevement

Heinz Hölzer-2
In reply to this post by Armén
total agreement ;)

[hidden email] schrieb:

> ML uses "->" instead of "=>" and since haXe syntax already uses the
> former, perhaps a dash is more appropriate than the "=" ?
>
> 2009/8/12 Heinz Hölzer <[hidden email]>:
>  
>> Yes it's just about syntax.
>>
>> I think there must be an alternative short form for functions, it's annoying
>> to write "function (a) return a>0" just for a short Boolean
>> Expression.
>>
>> [hidden email] schrieb:
>>    
>>> Is this purely syntactical construct? I mean, compiler would do
>>> exactly what it does with closures?
>>>
>>> When I wrote that topic on "var", I meant to express a need for
>>> "aliases", i.e. compiler assisted aliases for expressions, like "alias
>>> g = obj.graphics;"
>>>
>>> 2009/8/12 Heinz Hölzer <[hidden email]>:
>>>
>>>      
>>>> I would really like to see Lambda Expressions (or a shorter syntax for
>>>> them)
>>>> in haxe.
>>>>
>>>> I found the discussion about that in the topic "[haXe] Would "var"
>>>> keyword
>>>> be considered an example of imperative", and i would like
>>>> to hear what the community think about that.
>>>>
>>>> The concept is really simple, it would be just another way to write
>>>> anonymous functions.
>>>>
>>>> instead of
>>>>
>>>> function (a) { return "something"; } or function (a) return "something"
>>>>
>>>> you can write
>>>>
>>>> a => "something"
>>>>
>>>> or with more than one parameter
>>>>
>>>> (a,b) => a + b
>>>>
>>>> or with a block
>>>>
>>>> (a,b) = {
>>>>  if (a < b) return -1;
>>>>  if (a > b) return 1;
>>>>  return 0;
>>>> }
>>>>
>>>> Together with the using syntax and The Lambda class you can write nice
>>>> and
>>>> clean code:
>>>>
>>>> using Lambda;
>>>>
>>>> var a = new List<Int>();
>>>>
>>>> a.filter( a => a > 1 )
>>>>
>>>> instead of
>>>>
>>>> a.filter( function (a) return a > 1)
>>>>
>>>> or more advanced
>>>>
>>>> a.filter
>>>>
>>>> which i think is much more expressive and you can focus more on the what
>>>> than the how, especially when you combine expressions.
>>>> The syntax style is from C# and there are more C# examples on the web:
>>>>
>>>> http://blogs.msdn.com/ericwhite/pages/Lambda-Expressions.aspx
>>>>
>>>> http://blah.winsmarts.com/2006/05/19/demystifying-c-30--part-4-lambda-expressions.aspx
>>>> http://www.codeproject.com/KB/cs/explore_lamda_exp.aspx
>>>>
>>>>
>>>> what do you think about that? Would it be a good Idea to implement this
>>>> Syntax in haxe?
>>>>
>>>> --
>>>> haXe - an open source web programming language
>>>> http://haxe.org
>>>>
>>>>
>>>>        
>>>      
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>>
>>    
>
>  


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion: Lambda Expressions like a => a > 0 as haxe imprevement

Simon Krajewski
In reply to this post by Mark de Bruijn | Dykam
Mark de Bruijn schrieb:
> Simon, it is easily resolved as it is just an expression to be parsed,
> following the normal rules but with the => having a high priority. Can
> you give me a case where that would not work?
You're right, for some reason I sort of ignored the whole anonymous idea
and thought you wanted to do something like this for single instruction
functions:

var plus = (a,b) => a+b
plus(4,6);

But even then you could just put the ; there, so everything's fine.
Sorry for confusing this.

Regards
Simon



--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion: Lambda Expressions like a => a > 0 as haxe imprevement

Mark de Bruijn | Dykam
Yeah, that would just be var plus = (a, b) => a + b;

The nice thing of this is that because of the absence of bloating syntax, the functions become much more expressive and amazing uses appear.

On Wed, Aug 12, 2009 at 5:57 PM, Simon Krajewski <[hidden email]> wrote:
Mark de Bruijn schrieb:

Simon, it is easily resolved as it is just an expression to be parsed, following the normal rules but with the => having a high priority. Can you give me a case where that would not work?
You're right, for some reason I sort of ignored the whole anonymous idea and thought you wanted to do something like this for single instruction functions:

var plus = (a,b) => a+b
plus(4,6);

But even then you could just put the ; there, so everything's fine. Sorry for confusing this.


Regards
Simon



--
haXe - an open source web programming language
http://haxe.org



--
Mark

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion: Lambda Expressions like a => a > 0 as haxe imprevement

Simon Richardson
Just wondering how nesting of Lambda are possible and would you even permit it?

var sum = (a, b) => (a = (a) => a * 2), (b = (b) => b / 3), a + b;


Cheers
Si

On 12 Aug 2009, at 17:12, Mark de Bruijn wrote:

Yeah, that would just be var plus = (a, b) => a + b;

The nice thing of this is that because of the absence of bloating syntax, the functions become much more expressive and amazing uses appear.

On Wed, Aug 12, 2009 at 5:57 PM, Simon Krajewski <[hidden email]> wrote:
Mark de Bruijn schrieb:

Simon, it is easily resolved as it is just an expression to be parsed, following the normal rules but with the => having a high priority. Can you give me a case where that would not work?
You're right, for some reason I sort of ignored the whole anonymous idea and thought you wanted to do something like this for single instruction functions:

var plus = (a,b) => a+b
plus(4,6);

But even then you could just put the ; there, so everything's fine. Sorry for confusing this.


Regards
Simon



--
haXe - an open source web programming language
http://haxe.org



--
Mark
--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion: Lambda Expressions like a => a > 0 as haxe imprevement

Heinz Hölzer-2
I don't think so, I see the Lambda Syntax just as a shortcut for the
function syntax, so everything that works for the long
function syntax is also possible for the Lambda Syntax.

It's just about Syntax and not about new semantics.

// actual way
var func = function (a, b) return (function(a) return a * 2)(a) +
(function (b) return b / 3)(b);
       
// new way
var func = (a, b) => (a => a * 2)(a) + (b => b / 3)(b);


you call functions just like before, it's just a transformation.
I would not say that this is totally perfect, but more readable than
actually.

And this shouldn't be to difficult to implement.




Simon Richardson schrieb:

> Just wondering how nesting of Lambda are possible and would you even
> permit it?
>
> var sum = (a, b) => (a = (a) => a * 2), (b = (b) => b / 3), a + b;
>
>
> Cheers
> Si
>
> On 12 Aug 2009, at 17:12, Mark de Bruijn wrote:
>
>> Yeah, that would just be var plus = (a, b) => a + b;
>>
>> The nice thing of this is that because of the absence of bloating
>> syntax, the functions become much more expressive and amazing uses
>> appear.
>>
>> On Wed, Aug 12, 2009 at 5:57 PM, Simon Krajewski <[hidden email]
>> <mailto:[hidden email]>> wrote:
>>
>>     Mark de Bruijn schrieb:
>>
>>         Simon, it is easily resolved as it is just an expression to
>>         be parsed, following the normal rules but with the => having
>>         a high priority. Can you give me a case where that would not
>>         work?
>>
>>     You're right, for some reason I sort of ignored the whole
>>     anonymous idea and thought you wanted to do something like this
>>     for single instruction functions:
>>
>>     var plus = (a,b) => a+b
>>     plus(4,6);
>>
>>     But even then you could just put the ; there, so everything's
>>     fine. Sorry for confusing this.
>>
>>
>>     Regards
>>     Simon
>>
>>
>>
>>     --
>>     haXe - an open source web programming language
>>     http://haxe.org
>>
>>
>>
>>
>> --
>> Mark
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion: Lambda Expressions like a => a > 0 as haxe imprevement

Mark de Bruijn | Dykam
@Simon:
var sum = (a, b) => (a = (a) => a * 2), (b = (b) => b / 3), a + b; <- What is this? Let's see what i can make of it when dissecting:
var sum = function(a, b) { (a = function(a) { return a * 2; }), (b = function(b) { return b / 3; }), a+b; <- not valid. What are you trying to do? Or did you want to do what Heinz wrote?

Currently porting a subset of Linq, the backend has become a little bloated as there is nu yield, fine lambda and overloading. I'll put a P.o.C. online today or tomorrow.

2009/8/12 Heinz Hölzer <[hidden email]>
I don't think so, I see the Lambda Syntax just as a shortcut for the function syntax, so everything that works for the long
function syntax is also possible for the Lambda Syntax.

It's just about Syntax and not about new semantics.

// actual way
var func = function (a, b) return (function(a) return a * 2)(a) + (function (b) return b / 3)(b);
     // new way
var func = (a, b) => (a => a * 2)(a) + (b => b / 3)(b);


you call functions just like before, it's just a transformation.
I would not say that this is totally perfect, but more readable than actually.

And this shouldn't be to difficult to implement.




Simon Richardson schrieb:
Just wondering how nesting of Lambda are possible and would you even permit it?

var sum = (a, b) => (a = (a) => a * 2), (b = (b) => b / 3), a + b;


Cheers
Si

On 12 Aug 2009, at 17:12, Mark de Bruijn wrote:

Yeah, that would just be var plus = (a, b) => a + b;

The nice thing of this is that because of the absence of bloating syntax, the functions become much more expressive and amazing uses appear.

On Wed, Aug 12, 2009 at 5:57 PM, Simon Krajewski <[hidden email] <mailto:[hidden email]>> wrote:

   Mark de Bruijn schrieb:

       Simon, it is easily resolved as it is just an expression to
       be parsed, following the normal rules but with the => having
       a high priority. Can you give me a case where that would not
       work?

   You're right, for some reason I sort of ignored the whole
   anonymous idea and thought you wanted to do something like this
   for single instruction functions:

   var plus = (a,b) => a+b
   plus(4,6);

   But even then you could just put the ; there, so everything's
   fine. Sorry for confusing this.


   Regards
   Simon



   --    haXe - an open source web programming language
   http://haxe.org




--
Mark
--
haXe - an open source web programming language
http://haxe.org



--
haXe - an open source web programming language
http://haxe.org



--
Mark

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion: Lambda Expressions like a => a > 0 as haxe imprevement

Simon Richardson
@Mark
var sum = function(a, b) { return c = function(a) { return a * 2; }, d = function(b) { return b / 2; }, c(a) + d(b); }

This is valid flash syntax, which is what I was getting at!
hmmm!



On 13 Aug 2009, at 12:06, Mark de Bruijn wrote:

@Simon:
var sum = (a, b) => (a = (a) => a * 2), (b = (b) => b / 3), a + b; <- What is this? Let's see what i can make of it when dissecting:
var sum = function(a, b) { (a = function(a) { return a * 2; }), (b = function(b) { return b / 3; }), a+b; <- not valid. What are you trying to do? Or did you want to do what Heinz wrote?

Currently porting a subset of Linq, the backend has become a little bloated as there is nu yield, fine lambda and overloading. I'll put a P.o.C. online today or tomorrow.

2009/8/12 Heinz Hölzer <[hidden email]>
I don't think so, I see the Lambda Syntax just as a shortcut for the function syntax, so everything that works for the long
function syntax is also possible for the Lambda Syntax.

It's just about Syntax and not about new semantics.

// actual way
var func = function (a, b) return (function(a) return a * 2)(a) + (function (b) return b / 3)(b);
     // new way
var func = (a, b) => (a => a * 2)(a) + (b => b / 3)(b);


you call functions just like before, it's just a transformation.
I would not say that this is totally perfect, but more readable than actually.

And this shouldn't be to difficult to implement.




Simon Richardson schrieb:
Just wondering how nesting of Lambda are possible and would you even permit it?

var sum = (a, b) => (a = (a) => a * 2), (b = (b) => b / 3), a + b;


Cheers
Si

On 12 Aug 2009, at 17:12, Mark de Bruijn wrote:

Yeah, that would just be var plus = (a, b) => a + b;

The nice thing of this is that because of the absence of bloating syntax, the functions become much more expressive and amazing uses appear.

On Wed, Aug 12, 2009 at 5:57 PM, Simon Krajewski <[hidden email] <mailto:[hidden email]>> wrote:

   Mark de Bruijn schrieb:

       Simon, it is easily resolved as it is just an expression to
       be parsed, following the normal rules but with the => having
       a high priority. Can you give me a case where that would not
       work?

   You're right, for some reason I sort of ignored the whole
   anonymous idea and thought you wanted to do something like this
   for single instruction functions:

   var plus = (a,b) => a+b
   plus(4,6);

   But even then you could just put the ; there, so everything's
   fine. Sorry for confusing this.


   Regards
   Simon



   --    haXe - an open source web programming language
   http://haxe.org




--
Mark
--
haXe - an open source web programming language
http://haxe.org



--
haXe - an open source web programming language
http://haxe.org



--
Mark
--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion: Lambda Expressions like a => a > 0 as haxe imprevement

Mark de Bruijn | Dykam
Don't know that syntax, so can't translate it. I prefer a valid haXe construction to translate into short-lambda.

On Thu, Aug 13, 2009 at 2:09 PM, Simon Richardson <[hidden email]> wrote:
@Mark
var sum = function(a, b) { return c = function(a) { return a * 2; }, d = function(b) { return b / 2; }, c(a) + d(b); }

This is valid flash syntax, which is what I was getting at!
hmmm!



On 13 Aug 2009, at 12:06, Mark de Bruijn wrote:

@Simon:
var sum = (a, b) => (a = (a) => a * 2), (b = (b) => b / 3), a + b; <- What is this? Let's see what i can make of it when dissecting:
var sum = function(a, b) { (a = function(a) { return a * 2; }), (b = function(b) { return b / 3; }), a+b; <- not valid. What are you trying to do? Or did you want to do what Heinz wrote?

Currently porting a subset of Linq, the backend has become a little bloated as there is nu yield, fine lambda and overloading. I'll put a P.o.C. online today or tomorrow.

2009/8/12 Heinz Hölzer <[hidden email]>
I don't think so, I see the Lambda Syntax just as a shortcut for the function syntax, so everything that works for the long
function syntax is also possible for the Lambda Syntax.

It's just about Syntax and not about new semantics.

// actual way
var func = function (a, b) return (function(a) return a * 2)(a) + (function (b) return b / 3)(b);
     // new way
var func = (a, b) => (a => a * 2)(a) + (b => b / 3)(b);


you call functions just like before, it's just a transformation.
I would not say that this is totally perfect, but more readable than actually.

And this shouldn't be to difficult to implement.




Simon Richardson schrieb:
Just wondering how nesting of Lambda are possible and would you even permit it?

var sum = (a, b) => (a = (a) => a * 2), (b = (b) => b / 3), a + b;


Cheers
Si

On 12 Aug 2009, at 17:12, Mark de Bruijn wrote:

Yeah, that would just be var plus = (a, b) => a + b;

The nice thing of this is that because of the absence of bloating syntax, the functions become much more expressive and amazing uses appear.

On Wed, Aug 12, 2009 at 5:57 PM, Simon Krajewski <[hidden email] <mailto:[hidden email]>> wrote:

   Mark de Bruijn schrieb:

       Simon, it is easily resolved as it is just an expression to
       be parsed, following the normal rules but with the => having
       a high priority. Can you give me a case where that would not
       work?

   You're right, for some reason I sort of ignored the whole
   anonymous idea and thought you wanted to do something like this
   for single instruction functions:

   var plus = (a,b) => a+b
   plus(4,6);

   But even then you could just put the ; there, so everything's
   fine. Sorry for confusing this.


   Regards
   Simon



   --    haXe - an open source web programming language
   http://haxe.org




--
Mark
--
haXe - an open source web programming language
http://haxe.org



--
haXe - an open source web programming language
http://haxe.org



--
Mark
--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org



--
Mark

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion: Lambda Expressions like a => a > 0 as haxe imprevement

Heinz Hölzer-2
In reply to this post by Simon Krajewski
Just working with Files and Filters, that's another good example for
better readability

Two Filters:

var dirs = dirContent.filter ( function (f) return isDir( baseDir + "/"
+ f ) );

var files = dirContent.filter( function (f) return !isDir( baseDir + "/"
+ f ) && isHxFile( f ) );


Would be:

var dirs = dirContent.filter ( f =>  isDir( baseDir + "/" + f ) );

var files = dirContent.filter( f => !isDir( baseDir + "/" + f ) &&
isHxFile( f ) );

It's just clearer when you look at them.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion: Lambda Expressions like a => a > 0 as haxe imprevement

Nicolas Cannasse
In reply to this post by Heinz Hölzer-2
Heinz Hölzer a écrit :
> I would really like to see Lambda Expressions (or a shorter syntax for
> them) in haxe.
[...]
> what do you think about that? Would it be a good Idea to implement this
> Syntax in haxe?

Every additional syntax adds complexity to the language. I can
understand that writing :

a => a > 0

is shorter than writing :

function(a) return a > 0

But it also makes reading haXe code more difficult for people that are
not used to the language (except I they know C# it seems).

I tend to be quite conservative about language syntax, unless it adds
additional features for the same price. And that's not the case here.

Nicolas


--
haXe - an open source web programming language
http://haxe.org
12