![]() | This is an archive of past discussions about Forth (programming language). Do not edit the contents of this page. If you wish to start a new discussion or revive an old one, please do so on the current talk page. |
Archive 1 |
Its name is derived from Mr. Moore's belief that it was a "fourth-generation computer language"
I believe this is wrong. Fourth-generation languages are declarative languages like SQL, which Forth is not, as far as I know. I believe that the inventor thought that Forth was the fourth higher computer language ever written. That is something completely different. Spektr 21:15, 2004 Jun 4 (UTC)
Mr. Moore thought that FORTH was a fourth generation language, even if it isn't so in fact. The article is correct. --Prosfilaes 06:58, 8 Jun 2004 (UTC)
The story I heard is that Forth was devised on an IBM computer which allowed only five-letter filenames (incredible nowadays, but true — I once worked on such a computer), and is so-called because the FIRST, SECND and THIRD attempts all failed to work; the FORTH was the one which worked, and the name stuck. Korax1214 15:49, 4 June 2007 (UTC)
On the Lisp programming language article we have decided that despite the varying orthography we will spell that language's name "Lisp" rather than "LISP". This reflects the common practice of current Lisp users. The language "Forth" is also sometimes spelled "FORTH". Which orthography is preferred among current Forth/FORTH users? --FOo 02:04, 21 Jun 2004 (UTC)
Reading this article reminds me of a fantasy that I read as a child whereby a teenager gets summoned to a world of magic to defeat an evil wizard. Noticing that wizards discover spells on a trial-and-error basis he realizes that he can create new spells simply by combining three basic spells. Now I know he was really a Forth programmer!
"Stack-oriented" seems far more important for Forth than "data-structured" in the main description. Data-structured doesn't seem nearly as common a term, either, and it's semi-redundant with "reflective" in there. Benhoyt 01:51, 28 October 2005 (UTC)
StepsTogether recently changed
to
I am not sure I agree with this change. As far as I can tell, the only people spelling Forth in all capital letters are the same people that also spell Lisp, Fortran and Ada in all capital letters. —Tobias Bergemann 07:50, 15 November 2005 (UTC)
Hi, 68.68.2.115, as for Talk:Microsoft .NET the comments in the main article have been formatted. Comments are expressed in the talk page, here.
Mark Hurd 05:52, 18 December 2005 (UTC)
The article claims "A well-designed Forth program reads like natural language". Without an example, this seems quite POV and depends on one's definition of "natural language". Can someone contribute a chunk of code to illustrate this claim? Thanks. --Ds13 07:45, 20 February 2006 (UTC)
0 ( Washing Machine Application ) HEX 1 7000 CONSTANT MOTOR 7006 CONSTANT DETERGENT 700A CONSTANT CLUTCH 2 7002 CONSTANT VALVE 7008 CONSTANT TIMER 7010 CONSTANT LEVEL 3 7004 CONSTANT FAUCETS DECIMAL 4 5 : ON ( port) -1 SWAP OUTPUT ; : OFF ( port) 0 SWAP OUTPUT ; 6 : SECONDS ( n) 1000 * MS ; : MINUTES ( n) 60 * SECONDS ; 7 : ADD ( port) DUP ON 10 SECONDS OFF ; 8 : TILL-FULL BEGIN LEVEL INPUT UNTIL ; 9 : DRAIN VALVE ON 3 MINUTES VALVE OFF ; 10 : AGITATE MOTOR ON 10 MINUTES MOTOR OFF ; 11 : SPIN CLUTCH ON MOTOR ON 5 MINUTES MOTOR OFF CLUTCH OFF ; 12 : FILL FAUCETS ON TILL-FULL FAUCETS OFF ; 13 : WASH FILL DETERGENT ADD AGITATE DRAIN ; 14 : RINSE FILL AGITATE DRAIN ; 15 : WASHER WASH SPIN RINSE SPIN ;
Hi BACbKA. I see you've reverted my edit as "incorrect" and you suggest that I did not test on a "standard Forth system". The great thing about Forth standards is there's so many to choose from! ;-) My edit was tested on Gforth, which is an implementation of ANS Forth. Seems "standard" enough to me. At any rate, the existing code that you put back does not product "the same output" as the article suggests. At least two things are incorrect in its output when I run that example: 1) there is a " after the !, 2) there's no carriage return at the end. Does that code really output correctly on your system? --Ds13 23:39, 23 February 2006 (UTC)
I didn't notice the ", sorry. I saw that the main change of the edit that I had reverted was changing something of the form .( whatever)
to ." whatever else"
, which is wrong since the ."
semantics is not defined in the interpretation state. The other two changes are fine, but they're only cosmetic (i.e., what will be output precisely in the end), whereas the .( vs ." difference can be something that will preclude anything from being printed properly! As for gforth, a lot of systems, gforth included, extend undefined areas of the language to support as much DWIMmery as possible, and this is one of the cases. Sorry to have told you "you should have tested it" when you actually had run it! --BACbKA 13:46, 24 February 2006 (UTC)
I've tinkered with these sections, but this bit could do with a rewrite; basically, moving the File System & Multitasking pieces under the Operating System heading and removing some of the repetitions; there are also parts in the Self (meta) and cross compilation and Implementation of a Forth System that I'm not happy with. Suggestions? Alex 15:35, 1 March 2006 (UTC)
In the example code section, there's a 5-line Python function, and then the same function written as a 1-liner in Forth:
: FLOOR5 ( n -- n' ) 1- 5 MAX ;
I know you're trying to show how terse Forth can be, but do we have to be so obviously biased? If you can use the MAX builtin for Forth, it's not really fair to avoid the max() builtin for Python:
def floor5(v): return max(v-1, 5)
—The preceding unsigned comment was added by 130.76.32.167 (talk • contribs) 04:24, 5 April 2006 (UTC2)
: fib ( n -- n' ) dup 1 > if dup 1- recurse swap 2 - recurse + then ;
def fib(n): if n < 2: return n else: return fib(n - 1) + fib(n - 2)
Actually, when I think on it, this may serve to contrast/compare better with the Forth example;
def fib(n): if n > 1: return fib(n - 1) + fib(n - 2) else: return n
Unfortunately, neither of the Forth examples shows the return of multiple values on the stack, something most other languages can only do via structures. Alex 13:43, 12 April 2006 (UTC)
/MOD ( numerator denominator -- mod div )
to be a great example for this. --IanOsgood 23:34, 10 July 2006 (UTC)Here are a few variants. The last one, fibo, returns two values per call.
: ifib ( n -- res ) 0 1 ROT 0 ?DO TUCK + LOOP NIP ; : rfib1 ( n a b -- res ) 2 PICK 0= IF NIP NIP ( b) EXIT ENDIF ROT 1- -ROT TUCK + RECURSE ; : rfib ( n -- res ) 0 1 rfib1 ; \ fibo n = fst (h n) \ h 0 = (1,0) \ h n | even n = (a^2+b^2,b*(2*a-b)) where (a,b) = h (n div 2) \ h n | odd n = (a*(2*b+a),a^2+b^2) where (a,b) = h (n div 2) : SQR ( a -- a^2 ) DUP * ; : H ( n -- res1 res2 ) DUP 0= IF DROP 1 0 EXIT ENDIF DUP 1 AND IF 2/ RECURSE 2DUP 2* OVER + * -ROT SQR SWAP SQR + ELSE 2/ RECURSE 2DUP SQR SWAP SQR + -ROT SWAP 2* OVER - * ENDIF ; : FIBO ( n -- res ) h DROP ; : TEST ( n -- ) LOCAL n CR ." iterative FIB : " TIMER-RESET 0 #1000000 0 DO DROP n ifib LOOP 0 .R ." , " .ELAPSED CR ." recursive FIB : " TIMER-RESET 0 #1000000 0 DO DROP n rfib LOOP 0 .R ." , " .ELAPSED CR ." recursive FIB2 : " TIMER-RESET 0 #1000000 0 DO DROP n fibo LOOP 0 .R ." , " .ELAPSED ; FORTH> 34 test iterative FIB : 9227465, 0.083 seconds elapsed. recursive FIB : 9227465, 0.201 seconds elapsed. recursive FIB2 : 9227465, 0.137 seconds elapsed. ok
--Mhx 15:07, 13 May 2006 (UTC)
http://quartus.net/products/forth/compare.shtml -- a decent example, using Quartus Forth for the Palm handhelds, compares Forth and C in a complete "HelloWorld.exe" application. The comparison is written by Neal Bridges ( find email for him at Quartus.net). Raystm2 02:40, 1 March 2007 (UTC)
> The rationale for postfix notation is that it is closer to the machine language the computer will eventually use, and should therefore be faster to execute.
Fast execution has nothing to do with this. IMHO, the real reason is that with RPN variables can remain nameless. There is thus an obvious space-saving advantage. 80.56.233.149 04:35, 6 April 2006 (UTC)
Re 1: When Forth began, no such optimization was possible and variable names would have cost a bulky and (ultimately) useless word header (additionally slowing down compilation). Hmmm, in the ol' days VARIABLEs would certainly have been *much* slower than a SWAP or an OVER. So you actually have a point (with respect to both compilation and execution speed) there.
Re 2: Here we come near the true reason (IMHO). I don't agree operator precedence is a problem for the compiler. A parser for integers (no strings, no floats, no nothing) is only a few lines. But keeping the precedence system / parser extensible with the user being free to add compiler words and CREATE DOES> tricks was surely impossible, given the constrained resources of early Forth compilers.
Re 3: I doubt very much Charles Moore designed Forth with real Forth hardware in mind. It's more likely that he wanted to eliminate a few, in his eyes, unnecessary compiler layers. Don't forget that optimization (in those days) meant multi-pass processing, disk files, and certainly no interactive debugging and inspection. In the compiler texts I know, they start with building an interpreter that executes stack code. The next step is a "simple" compiler for the stack code, and that is where incredible complexity begins. Once again, I must admit that the answer has to do something with speed. But not execution speed, compilation speed.
NB. Even on stack chips, the code executed is not *pure* Forth. So what 'language' does a C compiler for such a chip emit? IMHO, for any imaginable (solvable) problem one can write a pure Forth or pure C program, and, given enough perspiration, both language compilers will emit exactly the same machine (stack) instructions.
80.56.233.149 20:50, 7 April 2006 (UTC)
Re Re 2:That's the beauty of Forth.
I am not contradicting you! That feature of Forth (interactivity and extensibility) is essential and must be in anything that dares to call itself Forth. Apparently it is difficult to write a simple and compact implementation of an extensible infix interpreter/compiler.
Re Re 3:The code is just about pure Forth. The perspiration is all C's; Forth doesn't even break a sweat generating code for this kind of architecture. On x86 and register based machines designed for C (take a look at the Intel manuals!) then Forth has a lot more to do; using stack opcodes as an intermediate representation is difficult to optimise.
Everybody says this, I wonder where it comes from. It is very easy to compile stackcode on x86 (I am iForth's author, and also wrote pl0 and TinyKiss with various backends). The difficulty is when you start optimizing, and then the complexity for Forth and "something else" is comparable. Proof: how many good optimizers are there for Forth, and how long did it take them to get where they are now? An efficient stack chip will have a PICK primitive that will completely do away with user-written stack orderings (SWAP DUP ROT etc.) Another way to look at it is to ask yourself what useful *work* SWAP does... Nothing of course, so it can be optimized out.
—The preceding unsigned comment was added by 80.56.233.149 (talk • contribs) 08:12, 8 April 2006 (UTC2)
Forth reasons for RPN:
--IanOsgood 23:13, 10 July 2006 (UTC)
I would say the widely agreed benefits of forth are the interactivity (fast edit/test/debug cycle) and the power, which is primarily due to the extensibility.
Ideogram 04:27, 27 May 2006 (UTC)
How is Forth a .NET programming language? Ideogram 22:08, 29 May 2006 (UTC)
Never mind I saw the citation above. Ideogram 22:54, 29 May 2006 (UTC)
The C article uses the cover of K&R for its infobox image. I was thinking the cover of Starting Forth (2nd ed.) might make a good image here. Can anyone produce a good image and upload it? My copy is looking a bit ragged. Ideogram 22:53, 29 May 2006 (UTC)
There's an image on amazon.com [3].
It's of the first edition, and not great, but it's better than nothing. Anyone know how we can get a copy to use here? Ideogram 23:00, 29 May 2006 (UTC)
There's a request for more images. Anyone have any good ideas? Ideogram 23:02, 29 May 2006 (UTC)
The books from Books. tutorials, and classes should be moved to the References section. They also need ISBN numbers. There's also an article citation under History of Forth. Ideogram 03:21, 30 May 2006 (UTC)
Ideogram; there's a reference to LISP and ALGOL as influences on Forth. AFAIK, Moore never programmed in either LISP or ALGOL, and I can't see any features of ALGOL in Forth at all. If anything, it may have been influenced by Moore's bad experience with other programming languages. I'll ask on comp.lang.forth and see if Elizabeth Rather (the world's second Forth programmer, and author of some of this entry) can help out.
Plus, the major implementations; this is one of these areas where you'll get a whole bunch of people up in arms! Alex 16:02, 30 May 2006 (UTC)
I am planning on sending email to Moore asking for permission to use his photo and about why he chose RPN. Any other questions I should ask? And does he have a PhD, should I address him as Mr. Moore or Dr. Moore? Ideogram 20:28, 31 May 2006 (UTC)
The email address chipchuck@colorforth.com fails, but I did a whois on colorforth.com and got an email address from the registration information. Let's just hope it's not so choked with spam he abandoned it.
Here is the email I sent:
Dear Dr. Moore:
I am working on the Wikipedia article on Forth. We would like to ask you some questions. What would you say are the advantages of RPN that led you to use it? What other languages influenced you when developing Forth? Finally, we would like to use a picture of you for the article, perhaps the one you currently have on colorforth.com. We would need your permission and that of the photographer.
If you are interested, you can see the article at
http://en.wikipedia.orghttps://demo.azizisearch.com/lite/wikipedia/page/Forth
We would certainly love to have your help in improving it. You can easily edit the article directly without our intervention.
Thank you for your time,
Adam Kao
I have received a reply from Chuck. Here it is:
I'm not sure exactly how to work this material into the article. Ideogram 03:04, 12 June 2006 (UTC)
65.12.192.254 edited the main text as follows:
> Compiled Forth has the unique property of actually being smaller in size than hand optimized assembler.
As it stands, this makes no sense and will be seen as unsubstantiated propaganda. What are the compared programs trying to accomplish? Are they optimizing for size, for speed, for power consumption? For instance, it is quite easy to make program A smaller than program B when A is allowed to be slower.Mhx 21:02, 8 June 2006 (UTC)
we need these. Does anyone have a citation for the Byte special issue on Forth? Ideogram 06:24, 9 June 2006 (UTC)
Mhx you are awesome!!! Those citations were the biggest thing still missing!!! Ideogram 20:14, 19 June 2006 (UTC)
The remaining citation on multiprogramming can come from Brodie's Starting Forth (find appropriate chapter and verse). The citation on Forth programming can come from the online gForth manual. I have no time to look this up now, sorry. Mhx 04:53, 20 June 2006 (UTC)
The Featured Article Candidate commentators have recommended we reduce the number of external links (see that page for details). I expect the decisions on what to keep and what to cut will be controversial, especially for the implementations links which they recommend we cut "drastically." Help! Ideogram 21:28, 13 June 2006 (UTC)