Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

design of lambda type signatures

Name: Anonymous 2012-11-10 22:23

Hey /praha/, what do you guys look for in a lambda type signature?

I personally like to see their smile. No, i mean, homoiconicity and uniform definition and declaration.

Anyways, which would you rather use everyday?


function<int, int -> int> foo;

foo = [int a, int b -> int] {
  return a + b;
}


or perhaps


function<int | int, int> foo;

foo = [int | int, int] {
  return a + b;
}


or anything else? Comparisons to other languages would be appreciated.

Go-style: foo = [int a, int b] int { return a + b; }
Actionscript-style: foo = [a:int, b:int]:int { return a + b; }

Name: Anonymous 2012-11-13 8:28

I like the lambda syntax in D; it's similar to C#:


//Parameter types inferred, can be declared if desired
auto arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
auto res = arr.filter!(x => x < 5);
assert(equal(res, [0, 1, 2, 3, 4]));

auto sum = res.reduce!((a, b) => a + b);
assert(sum == 10);


Also, because of D's string mixins, there is an even terser syntax available for functions that expect a predicate.


auto twice = res.map!"a * 2";
assert(equal(res, [0, 2, 4, 6, 8]));

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List