[net.lang.forth] RRe: What's so good about FORTH?

keppel@pavepaws.UUCP (06/14/86)

In article <432@astroatc.UUCP> philm@astroatc.UUCP (Phil Mason) writes:
>* small size : theaded-code is about a small as you can get.

Pardon, but I've never quite understood what threaded-code is.
Could somebody give me an explanation of
	o what it is
	o why it is fast
	o why other major languages don't use it or don't admit to using it


Thanks much  (Followups to net.lang).

    ;-D avid  K eppel				    ..!ucbvax!pavepaws!keppel
		"Learning by Osmosis: Gospel in, Gospel out"

philm@astroatc.UUCP (Phil Mason) (06/16/86)

In article <634@ucbcad.BERKELEY.EDU> keppel@pavepaws.UUCP (David Keppel) writes:
>In article <432@astroatc.UUCP> philm@astroatc.UUCP (Phil Mason) writes:
>>* small size : theaded-code is about a small as you can get.
>
>Pardon, but I've never quite understood what threaded-code is.
>Could somebody give me an explanation of
>	o what it is
>	o why it is fast
>	o why other major languages don't use it or don't admit to using it
>

Threaded code is a interesting concept. If you have an algorithm, and express
the algorithm with nothing but subroutine calls, one could say that the code
is threaded. In FORTH, the subroutine calls are implicit. In a high-level
(non-assembly language) routine, a list of the addresses of all of the 
component operations, in the proper order, is sufficient to describe the
operation of the routine.

Threaded code is not by its nature fast. It is amazingly compact, however.
Speed is determined by the qualities of the threaded code interpreter and
the processor on which the interpreter runs. If subroutine calls are very
expensive time-wise on the processor, threaded code will REALLY gum up the
works.

FORTH appears to be the only major language that uses threaded code as the
primary means of expressing algorithms internally. Other languages and
applications do use threaded code but by no means even close to the extent
that FORTH does. Threaded code is used for compactness and simplicity.

- -

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Kirk  : Bones ?                |  Phil Mason, Astronautics Technical Center
Bones : He's dead Jim.         |  Madison, Wisconsin - "Eat Cheese or Die!"
- - - - - - - - - - - - - - - -|  
...seismo-uwvax-astroatc!philm |  I would really like to believe that my
...ihnp4-nicmad/               |  employer shares all my opinions, but . . . 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

ark@alice.UucP (Andrew Koenig) (06/17/86)

> FORTH appears to be the only major language that uses threaded code as the
> primary means of expressing algorithms internally. Other languages and
> applications do use threaded code but by no means even close to the extent
> that FORTH does. Threaded code is used for compactness and simplicity.

Have a look at the Spitbol compilers sometime.

philm@astroatc.UUCP (Phil Mason) (06/18/86)

In article <5654@alice.uUCp> ark@alice.UucP (Andrew Koenig) writes:
>> FORTH appears to be the only major language that uses threaded code as the
>> primary means of expressing algorithms internally. Other languages and
>> applications do use threaded code but by no means even close to the extent
>> that FORTH does. Threaded code is used for compactness and simplicity.
>
>Have a look at the Spitbol compilers sometime.

Are these compilers real or just facetiously named? If they are real,
what's the story on them. It's news to me.



-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Kirk  : Bones ?                |  Phil Mason, Astronautics Technical Center
Bones : He's dead Jim.         |  Madison, Wisconsin - "Eat Cheese or Die!"
- - - - - - - - - - - - - - - -|  
...seismo-uwvax-astroatc!philm |  I would really like to believe that my
...ihnp4-nicmad/               |  employer shares all my opinions, but . . . 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

philm@astroatc.UUCP (Phil Mason) (06/26/86)

In article <255@myrias.UUCP> mj@myrias.UUCP (Michal Jaegermann) writes:
>>Maybe I'm not seeing the point about "threaded" languages -- you don't see
>>C programmers claiming that the major advantage of C is that you can use
>
>A fact that Forth is "threaded" is not a part of a language definition
>but side-effect of the most popular implementation method.  It gives
>very compact and flexible code with an ease of extensions.  The method
>is far from beeing unique to Forth and there are some Forth
>implementations which are not exatly "threaded".  At least not in the
>sense described earlier in some response.  An extreme case is to have
>the whole Forth as a huge 'case' statement in C.  (Yes, I have seen
>something like that :-) ).
>

A neat concept is that Forth is a psuedo-code based system. The
inner interpreter of Forth actually handles the threaded object code. 
The raw code that makes up the outer Forth interpreter is just an application 
run on the Forth pseudo-machine (the inner interpreter). You can really
think of the innermost guts of Forth as kind of a machine language for the
portable threaded code stack machine and not be incorrect. That's one reason
why the inner interpreter can be written in any language as long as it can 
interpret the threaded code with which the outer interpreter is written.



-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Kirk  : Bones ?                |  Phil Mason, Astronautics Technical Center
Bones : He's dead Jim.         |  Madison, Wisconsin - "Eat Cheese or Die!"
- - - - - - - - - - - - - - - -|  
...seismo-uwvax-astroatc!philm |  I would really like to believe that my
...ihnp4-nicmad/               |  employer shares all my opinions, but . . . 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=