6 ms·
> 2) RPN has a short syntax for them << a -> a 2 + >> The syntax is slightly different. What it should be is this << -> a << a 2 + >> >> The arrow introduces
by mschaef 9y ago
> 2) RPN has a short syntax for them << a -> a 2 + >>
The syntax is slightly different. What it should be is this
<< -> a << a 2 + >> >>
The arrow introduces a binding form that captures the top n levels of the stack into n named local variables. (There's also a lower level implementation that forgoes the names in favor of a lookup-by-ordinal scheme that's a lot faster.)
The other notable difference from what you might expect is that the lexical environment is not captured:
Consider this function:
<< -> a << << a 2 + >> >> >>
What it returns is a function object that looks like this, except that 'a' is a local variable reference rather than the global variable reference it looks like:
<< a 2 + >>
Evaluating this results in an error, because while 'a' is represented as a local variable reference, the environment containing the local binding for 'a' is no longer available.
- agumonkey 9y agoYou're totally right. I already forgot the deails. I just put out my hp49.. god how I love these things. ps: I just found out the latest attempt I did last years was a var called REC = << -> U << U U EVAL >> >> .. pretty sure I was trying a fixpoint CPS factorial in RPN