Discussion:
=> Lambda shorthand syntax
Stephen R. van den Berg
2015-03-14 09:45:22 UTC
Permalink
Has anyone ever considered adding support for the => shorthand lambda
operator to Pike?

It's available in several languages. The docs for C# are here:
https://msdn.microsoft.com/en-us/library/bb397687(v=vs.110).aspx
--
Stephen.
Ralph Ritoch
2015-03-14 10:44:39 UTC
Permalink
I don't see it in the documentation but pike already has a syntax for
lambda expressions.

Example:

int main() {
function y = lambda(int x) { return x * x; };
write((string)y(5));
}

Good luck with the pursuit for more operators.

Best Regards,
Ralph Ritoch
Post by Stephen R. van den Berg
Has anyone ever considered adding support for the => shorthand lambda
operator to Pike?
https://msdn.microsoft.com/en-us/library/bb397687(v=vs.110).aspx
--
Stephen.
Stephen R. van den Berg
2015-03-14 10:59:23 UTC
Permalink
Post by Ralph Ritoch
I don't see it in the documentation but pike already has a syntax for
lambda expressions.
Yes, it does.
Post by Ralph Ritoch
Good luck with the pursuit for more operators.
It's a new shorthand that makes certain common lambda expressions
more readable (and is popular in other languages).
--
Stephen.
Ralph Ritoch
2015-03-14 11:38:15 UTC
Permalink
Stephen,

Until this operator is ready you can use a macro to get close to the syntax
you want.

#define f(x, y ...) lambda(y) { return x; }

int main() {
function y = f(x * y, int x, int y);
write((string)y(5,2));
}

This was more for fun than practical use, but it demonstrates that the
operator should be fairly easy to achieve.

Best Regards,
Ralph Ritoch
Post by Stephen R. van den Berg
Post by Ralph Ritoch
I don't see it in the documentation but pike already has a syntax for
lambda expressions.
Yes, it does.
Post by Ralph Ritoch
Good luck with the pursuit for more operators.
It's a new shorthand that makes certain common lambda expressions
more readable (and is popular in other languages).
--
Stephen.
Martin Bähr
2015-03-16 16:09:56 UTC
Permalink
Post by Stephen R. van den Berg
Has anyone ever considered adding support for the => shorthand lambda
operator to Pike?
https://msdn.microsoft.com/en-us/library/bb397687(v=vs.110).aspx
there is also the block syntax from smalltalk and ruby:
[ mixed arguments | code; ]
{ mixed arguments | code; }

i am not sure if there is really a big advantage of using
(mixed arguments) => { code; }
over
lambda(mixed arguments){ code; }

how does it help with readability?

greetings, martin.

Loading...