Re: Lambda syntax, etc

2009-02-19 Thread Kagamin
Denis Koroskin Wrote: > >> Could be used as follows: > >> > >> foo( (i) { ++i; } ); > > > > Holy shi- > > Now feel some real power, Luke. :) > > > > foo( i => ++i ); > > > >> foo((i){ ++i; }); // error > >> foo((i){ ++i; return;}); // unambiguous > >> foo((i){ return ++i;}); // unambig

Re: Lambda syntax, etc

2009-02-10 Thread bearophile
Kagamin: > There is no error here, since there's no <- operator, the construct is > unabiguous, it just looks weird. In Fortress the syntax of this expression is OK: x + 2 * 3 x + 2*3 This is a syntax error, because the spaces are misleading: x+2 * 3 Bye, bearophile

Re: Lambda syntax, etc

2009-02-10 Thread Kagamin
bearophile Wrote: > Kagamin: > > auto r = find(range, {a -> a.Weight <- 100}); > > Take a look at how the Fortress language manages spaces inside expressions. > It can find a syntax error there, because the spacing is misleading. There is no error here, since there's no <- operator, the constru

Re: Lambda syntax, etc

2009-02-10 Thread Kagamin
Kagamin Wrote: > > > auto r = find(range, {a -> a.Weight <- 100}); > > > > Take a look at how the Fortress language manages spaces inside expressions. > > It can find a syntax error there, because the spacing is misleading. > > There is no error here, since there's no <- operator, the construct

Re: Lambda syntax, etc

2009-02-10 Thread bearophile
Kagamin: > auto r = find(range, {a -> a.Weight <- 100}); Take a look at how the Fortress language manages spaces inside expressions. It can find a syntax error there, because the spacing is misleading. Bye, bearophile

Re: Lambda syntax, etc

2009-02-10 Thread Kagamin
grauzone Wrote: > > // syntax for lambda that contains a single expression, implicit return > > (this is the most common case): > > auto r = find!(a => a.Weight > 100)(range); > > I really like this one, but I'd prefer something like > > auto r = find(range, {a -> a.Weight > 100}); > > Note th

Re: Lambda syntax, etc

2009-02-09 Thread Nick Sabalausky
"grauzone" wrote in message news:gmpgod$fe...@digitalmars.com... > bearophile wrote: >> Let's play more; then what do you think about (all the following are >> legal): >> >> auto r1 = range.find({ x -> x.weight > 100 }); >> auto r2 = range.find({ x :: return x.weight > 100; }); >> auto r3 = rang

Re: Lambda syntax, etc

2009-02-09 Thread grauzone
bearophile wrote: grauzone Wrote: I really like this one, but I'd prefer something like > auto r = find(range, {a -> a.Weight > 100}); Note the -> instead of the =>, to avoid any ambiguities with the comparison operator. Let's play more; then what do you think about (all the following are l

Re: Lambda syntax, etc

2009-02-09 Thread bearophile
bearophile: > auto r1 = range.find((ArrayType1!(typeof(range)) x) { return x.weight > 100; > }); Better: auto r1 = range.find((BaseType1!(typeof(range)) x) { return x.weight > 100; }); Of course, you have to specify range twice there, and that's not good. Bye, bearophile

Re: Lambda syntax, etc

2009-02-09 Thread bearophile
grauzone Wrote: > I really like this one, but I'd prefer something like > > auto r = find(range, {a -> a.Weight > 100}); > > Note the -> instead of the =>, to avoid any ambiguities with the > comparison operator. Let's play more; then what do you think about (all the following are legal): auto

Re: Lambda syntax, etc

2009-02-09 Thread grauzone
// syntax for lambda that contains a single expression, implicit return (this is the most common case): auto r = find!(a => a.Weight > 100)(range); I really like this one, but I'd prefer something like > auto r = find(range, {a -> a.Weight > 100}); Note the -> instead of the =>, to avoid any a

Re: Lambda syntax, etc

2009-02-09 Thread bearophile
Jarrett Billingsley: > auto r = find!(\a -> a.Weight > 100)(range); > [...] > > something(\a, b > { > stmt1; > stmt2; > }); This looks better to me (but I don't know if this is the best syntax, it's just an idea): // syntax for lambda that contains a single expression, implicit return (

Re: Lambda syntax, etc

2009-02-09 Thread Jarrett Billingsley
On Mon, Feb 9, 2009 at 3:19 AM, Bartosz Milewski wrote: > bearophile Wrote: >> Now, back to the topic: putting arguments into a single () or {} instead of >> a (){ return ;} (or with the => of C#) helps the eye see a single visual >> object isntead of two, this helps the human parsing of the cod

Re: Lambda syntax, etc

2009-02-09 Thread Christopher Wright
Kagamin wrote: Christopher Wright Wrote: D: void foo(void delegate(int) dg); C#: delegate void SomeName(int i); void foo(SomeName dg); Does C# 3 fix this? I've seen the new syntax for defining delegates, but not for using them. C# got anough rope for this :) http://msdn.microsoft.com/en-us

Re: Lambda syntax, etc

2009-02-09 Thread Kagamin
Denis Koroskin Wrote: > That was just an example. Those short lambdas are often used as predicates. > Compare: > > findAll(array, (i) { i > 3; }); > findAll(array, (int i) { return i > 3; }); > well... you pwnd me :)

Re: Lambda syntax, etc

2009-02-09 Thread Kagamin
Christopher Wright Wrote: > D: > void foo(void delegate(int) dg); > > C#: > delegate void SomeName(int i); > void foo(SomeName dg); > > Does C# 3 fix this? I've seen the new syntax for defining delegates, but > not for using them. C# got anough rope for this :) http://msdn.microsoft.com/en-us/

Re: Lambda syntax, etc

2009-02-09 Thread Denis Koroskin
On Mon, 09 Feb 2009 13:24:46 +0300, Kagamin wrote: Denis Koroskin Wrote: Could be used as follows: foo( (i) { ++i; } ); Holy shi- Now feel some real power, Luke. :) foo( i => ++i ); foo((i){ ++i; }); // error foo((i){ ++i; return;}); // unambiguous foo((i){ return ++i;}); //

Re: Lambda syntax, etc

2009-02-09 Thread Kagamin
Denis Koroskin Wrote: > Could be used as follows: > > foo( (i) { ++i; } ); Holy shi- Now feel some real power, Luke. :) foo( i => ++i ); > foo((i){ ++i; }); // error > foo((i){ ++i; return;}); // unambiguous > foo((i){ return ++i;}); // unambiguous

Re: Lambda syntax, etc

2009-02-09 Thread Bartosz Milewski
bearophile Wrote: > Now, back to the topic: putting arguments into a single () or {} instead of a > (){ return ;} (or with the => of C#) helps the eye see a single visual object > isntead of two, this helps the human parsing of the code, improving visual > chunking and reducing noise. I also be

Re: Lambda syntax, etc

2009-02-06 Thread hsyl20
> > You can use several "_", for instance: > > scala> val a = List(10,5,2,48,75,84,96,85,3,21,52) > > a: List[Int] = List(10, 5, 2, 48, 75, 84, 96, 85, 3, 21, 52) > > > > scala> val b = a reduceLeft (_ + _) > > b: Int = 481 > > > > The only problem is if you want to change arg order. In this case

Re: Lambda syntax, etc

2009-02-05 Thread Chris Nicholson-Sauls
Robert Fraser wrote: BCS wrote: Reply to Yigal, Personally I prefer to have syntax for "blocks" like Ruby/smalltalk. given the following example function: int func(int a, delegate int(int) dg) { .. } // call func with [something in this spirit is my favorite]: func(someInt) { | int a, int b |

Re: Lambda syntax, etc

2009-02-05 Thread Robert Fraser
Christopher Wright wrote: C#: delegate void SomeName(int i); void foo(SomeName dg); Ugh, don't remind me!

Re: Lambda syntax, etc

2009-02-05 Thread Robert Fraser
BCS wrote: Reply to Yigal, Personally I prefer to have syntax for "blocks" like Ruby/smalltalk. given the following example function: int func(int a, delegate int(int) dg) { .. } // call func with [something in this spirit is my favorite]: func(someInt) { | int a, int b | return a+b; }; how

Re: Lambda syntax, etc

2009-02-05 Thread Nick Sabalausky
"Christopher Wright" wrote in message news:gmfsqa$311...@digitalmars.com... > Kagamin wrote: >> Yeah, C# lambdas are the killer feature. Slick, readable, C-compatible. >> Anders knows his job. Let's face it: delegate literals suck a little, >> mixins as delegates suck a lot, the former is too v

Re: Lambda syntax, etc

2009-02-05 Thread Christopher Wright
Kagamin wrote: Yeah, C# lambdas are the killer feature. Slick, readable, C-compatible. Anders knows his job. Let's face it: delegate literals suck a little, mixins as delegates suck a lot, the former is too verbose, the latter just sucks. C# delegates in C# 2.0 are annoying. I try not to use

Re: Lambda syntax, etc

2009-02-05 Thread BCS
Reply to Yigal, Personally I prefer to have syntax for "blocks" like Ruby/smalltalk. given the following example function: int func(int a, delegate int(int) dg) { .. } // call func with [something in this spirit is my favorite]: func(someInt) { | int a, int b | return a+b; }; how about requir

Re: Lambda syntax, etc

2009-02-05 Thread Chris Nicholson-Sauls
BCS wrote: Why use this: "func(someInt) { |a,b| return a+b; };" when you can reuse syntax and get this for the same amount of typeing "func(someInt) (a,b){ return a+b; };" While I know the compiler could (should) know the difference easily enough, my eyes want to parse that as a chained

Re: Lambda syntax, etc

2009-02-05 Thread Yigal Chripun
hsyl20 wrote: Nick Sabalausky Wrote: The first notation "_ % 2 == 0" has no boilerplate and Scala is statically typed (unlike Python). I like that very much, especially since you can use either the implicit _ or a manually named var. Although I would prefer something like "a", "b", etc, (or ma

Re: Lambda syntax, etc

2009-02-05 Thread BCS
Reply to Andrei, Kagamin wrote: Also, it is my perception (and not only mine) that C#'s creator completely missed the power of templates and generative programming. I have never met the man, but it is my impression that Anders didn't miss the power, he just doesn't care for the paradigm. I

Re: Lambda syntax, etc

2009-02-05 Thread BCS
Reply to Nick, This way, it's impossible to take valid code, add or remove a semicolon, and still have valid code (which I think was your main concern?). I think that way can be made even stronger my making the delegate/block need a trailing ';' (it's a function call after all) where a bare

Re: Lambda syntax, etc

2009-02-05 Thread Andrei Alexandrescu
grauzone wrote: What I see above is a smörgåsbord of syntaxes that shoot all over the proverbial barn door in the hope that one of them would strike someone's fancy. That strikes me as a rather lousily done job. Also, it is my I find this statement rather ironic, because you also seem to be

Re: Lambda syntax, etc

2009-02-05 Thread Denis Koroskin
On Thu, 05 Feb 2009 17:25:38 +0300, Andrei Alexandrescu wrote: Denis Koroskin wrote: On Thu, 05 Feb 2009 12:32:15 +0300, Kagamin wrote: bearophile Wrote: C#2 has lambdas, and C#3 adds closures and more type inferencing, so C#3+ supports the following syntaxes: (int i) => { return i % 3

Re: Lambda syntax, etc

2009-02-05 Thread grauzone
What I see above is a smörgåsbord of syntaxes that shoot all over the proverbial barn door in the hope that one of them would strike someone's fancy. That strikes me as a rather lousily done job. Also, it is my I find this statement rather ironic, because you also seem to be quite happy with

Re: Lambda syntax, etc

2009-02-05 Thread bearophile
Andrei Alexandrescu>Beyond that, I don't feel that changes like moving the parameters on one side or the other of "{" would be Earth-shattering.< As you have seen there are several possible syntaxes for anonymous functions/delegates/closures. And the current syntax already works, so I think non

Re: Lambda syntax, etc

2009-02-05 Thread Andrei Alexandrescu
Denis Koroskin wrote: On Thu, 05 Feb 2009 12:32:15 +0300, Kagamin wrote: bearophile Wrote: C#2 has lambdas, and C#3 adds closures and more type inferencing, so C#3+ supports the following syntaxes: (int i) => { return i % 3 == 1; } // C#2 i => i % 3 == 1 // C#3 i => { return i % 3 == 1; } /

Re: Lambda syntax, etc

2009-02-05 Thread Andrei Alexandrescu
Kagamin wrote: bearophile Wrote: C#2 has lambdas, and C#3 adds closures and more type inferencing, so C#3+ supports the following syntaxes: (int i) => { return i % 3 == 1; } // C#2 i => i % 3 == 1 // C#3 i => { return i % 3 == 1; } // C#3, with statements too To define a delegate o delegate cl

Re: Lambda syntax, etc

2009-02-05 Thread Denis Koroskin
On Thu, 05 Feb 2009 12:32:15 +0300, Kagamin wrote: bearophile Wrote: C#2 has lambdas, and C#3 adds closures and more type inferencing, so C#3+ supports the following syntaxes: (int i) => { return i % 3 == 1; } // C#2 i => i % 3 == 1 // C#3 i => { return i % 3 == 1; } // C#3, with statements

Re: Lambda syntax, etc

2009-02-05 Thread Kagamin
bearophile Wrote: > C#2 has lambdas, and C#3 adds closures and more type inferencing, so C#3+ > supports the following syntaxes: > (int i) => { return i % 3 == 1; } // C#2 > i => i % 3 == 1 // C#3 > i => { return i % 3 == 1; } // C#3, with statements too > To define a delegate o delegate closure:

Re: Lambda syntax, etc

2009-02-04 Thread Nick Sabalausky
"BCS" wrote in message news:a6268ff24108cb552c70a0a...@news.digitalmars.com... > Hello Nick, > >>> One #1 I'd be inclined to requier that the function be defined like >>> void DoIt(int delegate(int) dg...) >>> D laready has this syntax for Typesafe Variadic Functions >>> http://www.digi

Re: Lambda syntax, etc

2009-02-04 Thread hsyl20
Nick Sabalausky Wrote: > > The first notation "_ % 2 == 0" has no boilerplate and Scala is statically > > typed (unlike Python). > > > > I like that very much, especially since you can use either the implicit _ or > a manually named var. Although I would prefer something like "a", "b", etc, > (

Re: Lambda syntax, etc

2009-02-04 Thread Jarrett Billingsley
On Thu, Feb 5, 2009 at 1:20 AM, Nick Sabalausky wrote: > > > > Oh, and last semicolon of a function should be optional :-) > > > >{ int x; int y :: return x+y } > > > > Now there's a language war waiting to happen ;) Psh! All that has to happen grammatically is that instead of using a raw se

Re: Lambda syntax, etc

2009-02-04 Thread Bill Baxter
On Thu, Feb 5, 2009 at 3:20 PM, Nick Sabalausky wrote: >> K&R was like >> int add(x,y) >>int x; >>int y; >> { return x+y } >> > > Oh that's right, I knew it was something funky like that. (That would be a > "bad redundancy". /me nods to Walter's Dobbs article.) Well the n

Re: Lambda syntax, etc

2009-02-04 Thread Nick Sabalausky
"Bill Baxter" wrote in message news:mailman.651.1233813474.22690.digitalmar...@puremagic.com... > On Thu, Feb 5, 2009 at 2:56 PM, Bill Baxter wrote: >> On Thu, Feb 5, 2009 at 2:30 PM, Nick Sabalausky wrote: > 2) A ruby-like syntax for delegate literals : {|a,b| return a+b;} I don'

Re: Lambda syntax, etc

2009-02-04 Thread BCS
Hello Nick, One #1 I'd be inclined to requier that the function be defined like void DoIt(int delegate(int) dg...) D laready has this syntax for Typesafe Variadic Functions http://www.digitalmars.com/d/1.0/function.html I'm not quite convinced either way on this. For what reasons do you th

Re: Lambda syntax, etc

2009-02-04 Thread Bill Baxter
On Thu, Feb 5, 2009 at 2:56 PM, Bill Baxter wrote: > On Thu, Feb 5, 2009 at 2:30 PM, Nick Sabalausky wrote: 2) A ruby-like syntax for delegate literals : {|a,b| return a+b;} >>> >>> I don't like that >>> >> >> The thing I like about that is that it makes it much more clear at a glance >> tha

Re: Lambda syntax, etc

2009-02-04 Thread Bill Baxter
On Thu, Feb 5, 2009 at 2:30 PM, Nick Sabalausky wrote: >>> 2) A ruby-like syntax for delegate literals : {|a,b| return a+b;} >> >> I don't like that >> > > The thing I like about that is that it makes it much more clear at a glance > that the "a,b" or "int a, int b" is associated with the code blo

Re: Lambda syntax, etc

2009-02-04 Thread Nick Sabalausky
"Nick Sabalausky" wrote in message news:gmdtjl$2f4...@digitalmars.com... > > // "func" used to disambiguate between function call and function > declaration > func add { |int <- int x, int y | >return x+y; > } > This one has the added benefit of making it easy to distinguish between an att

Re: Lambda syntax, etc

2009-02-04 Thread Nick Sabalausky
"BCS" wrote in message news:78ccfa2d39bdc8cb54edb3210...@news.digitalmars.com... > Reply to Bill, > >>> I was about to say the same thing, but I think Yigal was just mixing >> two distinct suggestions together: >> 1) the trailing delegates proposal (aka ruby block) and > > I like that > Then we'

Re: Lambda syntax, etc

2009-02-04 Thread Nick Sabalausky
"hsyl20" wrote in message news:gmd862$174...@digitalmars.com... >> In D (with dlibs) it is: >> >> auto a = [97, 44, 67, 3, 22, 90, 1, 77, 98, 1078, 6, 64, 6, 79, 42]; >> auto b = a.filter((int i){return !(i % 2);}); >> >> In Python: >> >> a = [97, 44, 67, 3, 22, 90, 1, 77, 98, 1078, 6, 64, 6, 79,

Re: Lambda syntax, etc

2009-02-04 Thread bearophile
hsyl20: > In Scala : > The first notation "_ % 2 == 0" has no boilerplate and Scala is statically > typed (unlike Python). There's a subtle line between "no boilerplate" and "magic (variables)", and the Python syntax is less magic there. So thanks but no thanks. I like the type system of Scala,

Re: Lambda syntax, etc

2009-02-04 Thread hsyl20
> In D (with dlibs) it is: > > auto a = [97, 44, 67, 3, 22, 90, 1, 77, 98, 1078, 6, 64, 6, 79, 42]; > auto b = a.filter((int i){return !(i % 2);}); > > In Python: > > a = [97, 44, 67, 3, 22, 90, 1, 77, 98, 1078, 6, 64, 6, 79, 42] > b = [x for x in a if not(i % 2)] In Scala : val a = List(97, 44

Re: Lambda syntax, etc

2009-02-04 Thread Yigal Chripun
Bill Baxter wrote: On Thu, Feb 5, 2009 at 7:26 AM, BCS wrote: Reply to Nick, "Yigal Chripun" wrote in message news:gmd0u8$fg...@digitalmars.com... Andrei Alexandrescu wrote: BCS wrote: Hello bearophile, I've taken a look at the syntax for lambda in other C-like languages. This is fro

Re: Lambda syntax, etc

2009-02-04 Thread BCS
Reply to Bill, I was about to say the same thing, but I think Yigal was just mixing two distinct suggestions together: 1) the trailing delegates proposal (aka ruby block) and I like that 2) A ruby-like syntax for delegate literals : {|a,b| return a+b;} I don't like that One #1 I'd be in

Re: Lambda syntax, etc

2009-02-04 Thread Bill Baxter
On Thu, Feb 5, 2009 at 7:26 AM, BCS wrote: > Reply to Nick, > >> "Yigal Chripun" wrote in message >> news:gmd0u8$fg...@digitalmars.com... >> >>> Andrei Alexandrescu wrote: >>> BCS wrote: > Hello bearophile, > >> I've taken a look at the syntax for lambda in other C-like

Re: Lambda syntax, etc

2009-02-04 Thread BCS
Reply to Nick, "Yigal Chripun" wrote in message news:gmd0u8$fg...@digitalmars.com... Andrei Alexandrescu wrote: BCS wrote: Hello bearophile, I've taken a look at the syntax for lambda in other C-like languages. This is from Functional Java: http://functionaljava.org/examples#Array.filte

Re: Lambda syntax, etc

2009-02-04 Thread Nick Sabalausky
"Yigal Chripun" wrote in message news:gmd0u8$fg...@digitalmars.com... > Andrei Alexandrescu wrote: >> BCS wrote: >>> Hello bearophile, >>> I've taken a look at the syntax for lambda in other C-like languages. This is from Functional Java: http://functionaljava.org/examples#Array.fi

Re: Lambda syntax, etc

2009-02-04 Thread Yigal Chripun
Andrei Alexandrescu wrote: BCS wrote: Hello bearophile, I've taken a look at the syntax for lambda in other C-like languages. This is from Functional Java: http://functionaljava.org/examples#Array.filter In Functional Java you can write this D syntax: (int i, int j) { return i % 3 == j; } as:

Re: Lambda syntax, etc

2009-02-04 Thread Nick Sabalausky
"Andrei Alexandrescu" wrote in message news:gmclr4$2q3...@digitalmars.com... > BCS wrote: >> Hello bearophile, >> >>> I've taken a look at the syntax for lambda in other C-like languages. >>> This is from Functional Java: >>> http://functionaljava.org/examples#Array.filter >>> >>> In Functional J

Re: Lambda syntax, etc

2009-02-04 Thread Andrei Alexandrescu
BCS wrote: Hello bearophile, I've taken a look at the syntax for lambda in other C-like languages. This is from Functional Java: http://functionaljava.org/examples#Array.filter In Functional Java you can write this D syntax: (int i, int j) { return i % 3 == j; } as: { int i, int j => i % 3 ==

Re: Lambda syntax, etc

2009-02-04 Thread BCS
Hello bearophile, I've taken a look at the syntax for lambda in other C-like languages. This is from Functional Java: http://functionaljava.org/examples#Array.filter In Functional Java you can write this D syntax: (int i, int j) { return i % 3 == j; } as: { int i, int j => i % 3 == j } That s

Lambda syntax, etc

2009-02-04 Thread bearophile
I've taken a look at the syntax for lambda in other C-like languages. This is from Functional Java: http://functionaljava.org/examples#Array.filter In Functional Java you can write this D syntax: (int i, int j) { return i % 3 == j; } as: { int i, int j => i % 3 == j } It's shorter and less clutte