bdewbank@ihlpg.ATT.COM (Ewbank) (03/31/88)
Hi - I've been hoping that there would be a little more discussion in this group. Guess I'll have to stir the embers :-). What is the programming language forth, and what is it best used for? I know that it is a "threaded language", but that's the extent of my knowledge of the language. -- Bryan Ewbank UUCP: ..{ihnp4,moss,cbosgd}!ihlpg!bdewbank AT&T Bell Labs VOICE: 312/979-5146 Naperville, IL ZIP: 60566
bts@sas.UUCP (Brian T. Schellenberger) (04/06/88)
I usually try to reply to most news items instead of posting, but since this newsgroup is *so* dead, I might as well post (zero--count 'em, zero messages in the past week!) Forth is Charles Moore's gift to programming :-) The closest to another language I can think of is: Lisp, backwards and without parentheses. "Of course," you say. It is a stack-based language. All the arguments are passed on the stack. This has the advantage that Forth "words" (Forth's names for both "functions" and "operators") can both take and *return* multiple values. It also has the advantage (like Lisp) that no distinction need be made between built-in "operators" and user-defined "functions": both deal with arguments in exactly the same way. It has the disadvantage that you have to remember where things are, rather than referring to items by name. The other distinctive characteristic of Forth (technically, this is a feature of most Forth implementations, but I don't think most Forth programmers would like the language without this feature) is that it incrementally compiles. You can do operations in-line, for example: 16 0 DO I . LOOP ( Forth for BASIC'S FOR I=0 to 15: PRINT I: NEXT ) Will print values in-line. Once you are satisfied, you can compile this: : DUMB-LOOP 16 0 DO I . LOOP ; defines a word which will print 0 .. 15. Now you can execute this "compiled" (actually threaded, but I'm trying not to get too bogged down in detail here) word by: DUMB-LOOP I have not gone into lots of the strangenesses here of Forth, but just tried to hit on what I consider Forth's most vital/unique properties. Here's a little gibberish for you, though . . . ( the favorite anti-Forth example: ) A @ B @ + C ! ( c = a + b ) : STUFF ( a b -- a+b a-b a/b a%b a*b ) 2DUP + -ROT 2DUP - -ROT 2DUP /MOD 2SWAP * ; 2DUP /MOD DROP IF ." non-zero" ELSE ." zero" THEN Disclaimer: I haven't tried any of these, nor have I used Forth in a couple of years (though I want to get back into it), nor I have I used a more modern Forth than Fig-FORTH with FORTH-79 extensions. Maybe I screwed up something bigtime. Nothing stirs up a newsgroup like gettting stuff all wrong. BUT these are all generally correct, and should give you a "feel" for the language. -- --Brian. (Brian T. Schellenberger) ...!mcnc!rti!sas!bts PET PEEVE: remember to keep included text small for us 1200-bauders . . .
ccplumb@watmath.waterloo.edu (Colin Plumb) (04/08/88)
My favourite forth definition, actually quite useful (it's required by F-83, I'm pretty sure) is: : ? @ . ; or, prettyprinted to the point of absurdity, for the benefit of beginners: : ? ( addr --) ( prints the value at address addr) ( usually used as "x ?" to print the contents of variable x)) @ ( val) ( "fetch") . ( ) ( "print") ; -- -Colin (watmath!ccplumb) Zippy says: Please come home with me... I have Tylenol!!