On 2/8/02 at 12:54 AM, Matt Schalit <[EMAIL PROTECTED]> wrote:
> What does a hello world in FORTH look like?
: HELLO_WORLD ." Hello, World!" ;
HELLO_WORLD
> Maybe could you also post an example that asks
> your full name then echos the first name and
> last name on different lines?
Text processing is not a basic part of FORTH - remember this is a
low-level language like C (its main competition) or Assembly...
It's been too long since I programmed Forth; here's an example that
asks a name and echos it back.
: GREET CR ." What's your name?" S0 @ 40 EXPECT
0 >IN ! 1 TEXT CR ." Hello, " PAD 40 -TRAILING
TYPE ." , I speak FORTH." ;
GREET
> btw, for Java, the two examples are easier to make
> as a gui app, but the answer for a terminal would be:
> Those would be compiled with:
>
> javac *.java
>
> which creates Hello.class and Fullname.class.
> Those are the executables, and they are run with:
>
> java Hello
> java Fullname
>
> Java is very case sensative, and classes start
> with a capital letter.
FORTH was case-sensitive, but some modern versions are not. FORTH is
an environment, not just a compiler - think of Smalltalk here.
The Forth prompt is:
ok
(cute, eh?) Comments are
( this is a FORTH comment - cute, eh?)
....or....
\ This is a one line comment....
The examples above define a new "word" that extends the language (by
using a : ....... ; construct) then execute it by name.
FORTH is what is called a "Threaded Language" - FORTH is made up of
pointers, or pointers to pointers. The "interpreter" is constantly
resolving pointers. In Modern Times, we have Postscript, OpenBOOT,
and the FreeBSD boot loader - all of which are FORTH or FORTH-like.
The corporation that embodies Forth - at least in terms of longevity,
and early language luminaries - is Forth, Inc, and they are still
going strong. Forth, in fact, is strong in embedded systems - you can
get a complete Forth interpreter, with editor, assembler, and quite a
few other things in way less than 64k. I can remember a 192k Apple II
multitasking under FORTH quite nicely....
--
David Douthitt
UNIX Systems Administrator
HP-UX, Unixware, Linux
[EMAIL PROTECTED]
_______________________________________________
Leaf-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/leaf-devel