Closed Kesanov closed 7 years ago
-> x y z { x + y + z }
is exactly equivalent to{ -> x y z; x + y + z }
Looks like it's just a yet another syntax sugar.
What do you mean it is just a syntax sugar. { -> a; a }
is lambda and you need abstraction algorithm to convert it to series of combinators.
So your question is “Why does Kitten support variables?”. Well, they are sometimes really convenient.
But aren't they also really inefficient? To my understanding the most efficient abstraction algorithm produces O(N^2) LOC. Going from 200e+3 to 40e+9 lines of code is pretty crazy (even if it is just theoretical worst case scenario).
Because they’re convenient and can help avoid writing brittle code in some cases.
I don’t use an abstraction algorithm, I just handle them like almost every other compiler—they’ll end up in registers or on the call stack.
So in other words -> a b; swap ... == -> b a; ...
?
If I understand your question, yes: swap -> a, b; …
= -> b, a; …
. The latest compiler doesn’t have a finished code generator yet, but swap
will be inlined, giving -> x, y; y x -> a, b; …
and then the redundant loads & stores will be simplified to -> b, a; …
(or even further, depending on …
). Those locals may be stored in registers if the types are small enough and there are registers available, or else spilled to the call stack, just as in a compiler for a C-like language.
Concatenative languages like Joy do not have lambdas. Why does kitten have them?
Are lambdas more powerful than
quote
andeval
([ .. ] i
)?