so i just saw this example given as a reason why
concatenative languages tend to be called "write-only":
f x y z = y¬≤ + x¬- |y|
drop dup dup *
rot3 dup *
swap - + ;
... snipped ...
He ends up writing the following:
lastly, nobody would ever write Forth like that anyway!
: ¬≤+ dup * swap dup * + ;
: y¬≤+x¬≤-|y| ( y x -- result )
tuck ¬≤+ swap abs - ;
Given a dislike of stack shufflers, a Retro implementation could be:
:f [ [ n:square ] bi@ + ] sip n:abs - ;
Assuming one knows the combinators, this is pretty straightforward,
but doesn't really resemble the original formula. I decided to write
a quick set of words to let me convert the original formula into
something more recognizable while still being RPN.
x: n:square y: n:square + y: n:abs - ;
This adds a / sigil that maps stack values to an internal set of
variables, whose values are returned by words with the variable names
followed by a colon.
The code follows.
And the test case: