Garth Goldwater
06/13/2019, 10:14 PMKartik Agaram
But concatenative programming is not perfect either. As shown in Why Concatenative Programming Matters, a simple expressionbecomesf(x, y, z) = x^2 + y^2 - abs(y)
drop dup dup × swap abs rot3 dup × swap − +
But why can't you just writeDo you have any sense of how that last program can be anywhere near correct?instead?drop dup (^2) + (^2) - abs
Garth Goldwater
06/13/2019, 11:16 PMKartik Agaram
Garth Goldwater
06/13/2019, 11:18 PMGarth Goldwater
06/13/2019, 11:19 PMGarth Goldwater
06/13/2019, 11:20 PMfyr
06/14/2019, 12:00 AMdip
from Factor yeah
like, (^2) + (^2)
is sugar for (id^2),(id^2) +
, where 3 4 f,g
applies f to 3 and g to 4(assuming they're both arity 1)Kartik Agaram
(^2)
couldn't possibly have anything to do with the +
at parse time. Doesn't this give up a lot of the benefits of concatenative programming? Reading up on Factor's dip
now.fyr
06/14/2019, 12:04 AMx y z | drop dup (^2) + (^2) - abs
x y | dup (^2) + (^2) - abs
x y y | (^2) + (^2) - abs
x y y | ((^2) + (^2)),abs -
x y | ((^2) + (^2)) (y | abs) -
x y | ((^2),(^2) +) (y | abs) -
x y | (^2),(^2) + (y | abs) -
x (^2) (y | ^2) + (y | abs) -
(x | ^2) (y | ^2) + (y | abs) -
(note ,
binds tighter than
)fyr
06/14/2019, 12:05 AMKartik Agaram
dip
has the decency to accept a quotation. This is just bonkers. Dismissing.fyr
06/14/2019, 12:23 AMa,b
in turn is sugar for {a} {b} ,
fair
or rather, this is a language defined on functions rather than values - but at least a,b,c
is a monoid 😶Garth Goldwater
06/14/2019, 12:41 AMGarth Goldwater
06/14/2019, 12:42 AMKartik Agaram
Garth Goldwater
06/14/2019, 12:43 AMwtaysom
06/14/2019, 2:17 AMf(x, y, z)
naturally awkward. (Perhaps if you could concatenate along multiple paths... spoiler, this leads somewhere.) Instead focus on the cool bits: (1) quotation feels comfy rather than mysterious, which comes from (2) you can basically factor out any sequence of words as a new word.Garth Goldwater
06/14/2019, 5:13 PMwtaysom
06/17/2019, 4:18 AMdrop dup dup × swap abs rot3 dup × swap − +
. Instead of stack twiddling, use can use geometry: drop
becomes a path the goes away, dup
is a branch, `swap`and rot3
reorder things.Garth Goldwater
06/17/2019, 2:43 PMKartik Agaram
wtaysom
06/17/2019, 3:42 PMx x * y y * + y abs -
. 😮wtaysom
06/17/2019, 3:53 PMx x * → x2
y y * → y2
x2 y2 + → x2py2
y abs → yy
x2py2 yy -
Now you end up close to A-normal form. Of course, the concatenative feel is lost somewhere along the way 😏.Kartik Agaram
locals
feel like something to be used very sparingly. Better to go with the grain of the platform you chose.
Yes, some things are hard to write clearly. Then we do what we do in any language: wrap it in a function, slap on a comment and shove it under the carpet. And if you find yourself doing this a lot, look around. You're probably working in a large team inheriting an old codebase you aren't empowered to make radical changes to. In which case a new language or new syntax ideas aren't going to help you.