Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!cs.utexas.edu!uunet!zephyr.ens.tek.com!tekcrl!tekgvs!toma From: toma@tekgvs.LABS.TEK.COM (Tom Almy) Newsgroups: comp.lang.forth Subject: Re: Random comments Message-ID: <5693@tekgvs.LABS.TEK.COM> Date: 3 Aug 89 15:01:05 GMT References: <10425@dasys1.UUCP> Reply-To: toma@tekgvs.LABS.TEK.COM (Tom Almy) Organization: Tektronix, Inc., Beaverton, OR. Lines: 36 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? The prefix "D" refers to double integer (typically 32 bit in a 16 bit FORTH implementation), while the prefix "2" refers to a pair of integers. A double integer is a subclass of a pair of integers -- as a practical example, a pair of integers can be used to express a ratio used in scaling with */: 2VARIABLE Ratio : setRatio ( numerator denominator -- ) Ratio 2! ; : scaleValue ( value -- scaledValue ) Ratio 2@ */ ; In this application, use of D! and D@ would be confusing. There is a practical reason to have both D@ and 2@ (etc). LMI UR/FORTH 386 implements both operations, and they are not the same! The 83 standard defines 2@ such that the lower address integer becomes top of stack, and the next integer becomes second on stack. In the 80386 (and other Intel architectures), the most significant portions of numbers are stored at the highest addresses. This means that using double integers will store into memory wrong, causing problems with the OS interface or interfacing with other language programs. D@ and D! access memory in Intel standard order. I also mind that DO loops up to, >not including the limit - it's not intuitive. Every new standard seems to have a new way of handling DO loops (I don't know if the ANSI standard will be different). It may not be very intuitive, but the reason is that indexing is 0 based, so that loops typically have an initial value of 0; to loop n times you execute "n 0 DO". Tom Almy toma@tekgvs.labs.tek.com I have a commercial connection with Laboratory Microsystems.