evincarofautumn / kitten

A statically typed concatenative systems programming language.
http://kittenlang.org/
Other
1.1k stars 42 forks source link

Why does kitten have variables? #194

Closed Kesanov closed 7 years ago

Kesanov commented 7 years ago

Concatenative languages like Joy do not have lambdas. Why does kitten have them?

Are lambdas more powerful than quote and eval ([ .. ] i)?

suhr commented 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.

Kesanov commented 7 years ago

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.

suhr commented 7 years ago

So your question is “Why does Kitten support variables?”. Well, they are sometimes really convenient.

Kesanov commented 7 years ago

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).

evincarofautumn commented 7 years ago

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.

Kesanov commented 7 years ago

So in other words -> a b; swap ... == -> b a; ...?

evincarofautumn commented 7 years ago

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.