Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!crdgw1!sunbelt!eaker From: eaker@sunbelt.crd.ge.com (Charles E Eaker) Newsgroups: comp.lang.forth Subject: Re: Random comments Message-ID: <1483@crdgw1.crd.ge.com> Date: 3 Aug 89 19:20:57 GMT References: <10425@dasys1.UUCP> Sender: news@crdgw1.crd.ge.com Reply-To: eaker@sunbelt.crd.ge.com (Charles E Eaker) Organization: General Electric Corp. R&D, Schenectady, NY Lines: 50 In article <10425@dasys1.UUCP> aj-mberg@dasys1.UUCP (Micha Berger) writes: >As someone new (less than 1 month, only have one working program - life) >to FORTH, 2 things really bug me. Why is it that we have 2!, 2DUP, 2CONSTANT, >but D. ? It seems inconsistant. You can't use 2 as a prefix across the board >(2+ and 2* are taken) but why not use D? Here's why. The prefix 2 generally means operate on 2 things of the usual size. The "usual size" in Forth has traditionally been a 16-bit "cell". Note that the operations 2!, 2DUP, and 2CONSTANT could care less what the 2 cells are interpreted to be. They could be two single numbers or 1 double number or 4 characters or one or more bit strings representing a set or representing a packed record structure or representing a date. But the dot operation which prints its operand must interpret the operand's contents. D. interprets two cells as being one double number. Another operation, say .TIME might interpret the two cells as representing seconds since some specified moment. I suppose a reasonable action for 2. would be to print the two cells as two consecutive single numbers. [What bugs ME is the traditional asymetry between D. and ." and the inclination to use the dot as a prefix in other print words such as .TIME . Instead, I think that the dot should uniformly be a suffix so that to print something right adjusted in a field whose width is on the stack we would use D.R and ".R and TIME.R but I'm afraid that using dot as a prefix to mean print is now too deeply ingrained.] > I also mind that DO loops up to, >not including the limit - it's not intuitive. > On the contrary, I find DO loop limits in Forth to be quite intuitive. I always get it right in Forth, I never get it right in Pascal, I often get it right in C. A limit, after all, is easily thought of as something which is never quite reached. If you want to initialize SIZE cells of an array, for example, starting at address ARRAY with the pattern PAT, you would use: ARRAY SIZE + ARRAY DO I PAT ! LOOP otherwise you would constantly have to subtract one: ARRAY SIZE + 1- ARRAY DO I PAT ! LOOP which strikes me as being an unnecessary and counter-intuitive nuisance in a piece of code that becomes a cliche in any array processing application. (Or would you rather the value of SIZE be one less than the actual size of the array? That's even more counter-intuitive.) For being new to Forth, you're asking good questions. Chuck Eaker | eaker@sunbelt.crd.ge.com Software Engineering Program | eaker@crdgw1.crd.ge.com GE Corporate Research & Development Center | eaker@crdgw1.UUCP P.O. Box 8, K-1 3C12 Schenectady, NY 12301 | 518 387-5964