1. Re: [If/then and sequences...]
- Posted by David Cuny <dcuny at LANSET.COM>
Aug 31, 2000
-
Last edited Sep 01, 2000
Kat wrote:
> Any way to do [FORTH] in Eu?
Coding a FORTH-like language in Euphoria would be fairly easy. Since FORTH
is a threaded language, code body is simply stored as a list of jump
addresses. Instead, Euphoria could store the code body as a list of indexes.
Built-in routines could be indicated by negative values.
For example, here's a Euphoria routine:
procedure foo( integer n )
? n + 12
end procedure
Here's essentially the same code in FORTH:
: foo 12 + . ;
Arguments are passed on the stack. Operations are reverse polish notation.
In this case, the literal 12 is pushed on the stack, the two top items are
added, and then the top of stack is popped and displayed.
Encoded in Euphoria, it might look like this:
{ "foo", LITERAL, 12, PLUS, DOT }
With this sort of approach, coding a TIL (threaded interpreted language) is
pretty easy. The problem with FORTH is that RPN is quite klunky to work
with, and stack operations can get tricky if there are more than 4 values on
the stack.
FORTH has some very baroque string operators; you would probably want to
define your own, since Euphoria would give you much more flexible handling
of strings.
-- David Cuny