[OT] Eternal programming
johnroth at ameritech.net
Thu Jul 12 17:04:37 CEST 2001
FORTH is an interesting language - Postscript is a distant relative.
Charles Moore originally wrote it to control telescopes; it's quite
widely used for process control, hence it's machine orientation.
In the hands of an expert, it's both incredibly productive and
Implementing FORTH in Python is an interesting project. In doing
an implementation you need to be very careful about distinguishing
among the artifacts of the current implementations and the core
language concepts - things like real memory references are an
artifact of implementations on real hardware, and don't have any
relevance to the core concepts.
I would think that you would want to start with a class named
"Word" that encapsulates a word: that is two sequences of instances
of class Word, one for run-time behavior and one for compile-time
behavior. The class should have methods RunTime() and
CompileTime(). Builtins should be subclasses of Word.
RunTime() simply loops through the Run sequence and invokes
each instance in turn. Let's see - loops. RunTime normally
returns +1, but it can return any offset; this is used to implement
looping and condition tests within a word.
For compile time, you need dictionaries: FORTH dictionaries map
very cleanly into Python dictionaries. The current compile time
environment is a list of FORTH dictionaries. The dictionary returns
the class instance that implements the word.
The execution time stack needs to be a global object - since
I'm not an OO purist, I'd make it a module level rather than a
singleton object. Tastes vary.
The return stack becomes the method invocation stack - it no longer
has an explicit representation. That hoses some of the tricks used to
make FOR loops work, and such, but alternate solutions can probably
be found for those. Or maybe not - we may need a separate return
stack that is only used for additional stuff, not the return addresses
The thing to watch out for is to avoid taking too much advantage of
Python tricks - portability means that it never quite fits into any
"Roman Suzi" <rnd at onego.ru> wrote in message
news:mailman.994779919.3199.python-list at python.org...
> On Tue, 10 Jul 2001, Mikael Olofsson wrote:
> > INTERCAL or Brainf***, anyone?
> The following script was written in half an hour
> (after I found this page:
> (Chemists are going to use Forth in nanotech programming. ;-)
> Sincerely yours, Roman A.Suzi
> - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru -
More information about the Python-list