Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!rpi!zaphod.mps.ohio-state.edu!usc!snorkelwacker!bloom-beacon!eru!luth!sunic!mcsun!unido!balu!gamber@cosmo.UUCP From: gamber@cosmo.UUCP (Johannes Teich) Newsgroups: comp.lang.forth Subject: +FOR...NEXT Keywords: loops Message-ID: <5628@balu.UUCP> Date: 8 May 90 10:49:05 GMT Sender: news@balu.UUCP Reply-To: gamber@cosmo.UUCP (Johannes Teich) Organization: CosmoNet, D-3000 Hannover 1, FRG Lines: 48 Forthers, I'm glad to have them both running: +--------+ +--------+ FOR | For | ?DO | ?Do | +--------+ +--------+ | offs |--. | offs |--. +--------+ | +--------+ | | |<-|-. | |<-|-. | | | | | | | | LEAVE | Leave ---|-|-. LEAVE | Leave ---|-|-. | | | | | | | | | | LEAVE | Leave ---|-|-. LEAVE | Leave ---|-|-. | | | | | | | | | | +--------+ | | | +--------+ | | | NEXT | Next |<-' | | LOOP | Loop | | | | +--------+ | | +--------+ | | | | offs |----' | | offs |--|-' | +--------+ | +--------+ | | | |<-----' | |<-' <-' FOR ... I ... LEAVE ... LEAVE ... NEXT ?DO ... I ... LEAVE ... LEAVE ... LOOP ( or DO and/or +LOOP ) There are 3 values on the return stack: jump-addr reference loop-index. The jump-addr is for LEAVE . The reference is for FORTH-83 & speed. The word I does a subtraction: R> DUP R@ - SWAP >R (it could be an addition like in Zen as well). The reference is always zero for FOR...NEXT , but must be present because of LEAVE , I and J . R@ is the same as I , then, but quicker. Now I think of something like n +FOR which sets the reference to n. 10 4 +FOR ... NEXT --> 9 8 7 6 5 4 doing the same as: 4 9 DO ... -1 +LOOP ( FORTH-83 ) The reference value would no longer be waisted. What do others think about +FOR or whatever it should be called? I prefer offsets over absolut addresses (as used in Pygmy), for I plan to shift the code in memory, and metacompiling becomes a little simpler, too. Btw, my 0 FOR...NEXT loops zero times. (In addition, cmFOR is available.) cheers, --Hannes | gamber@cosmo.uucp | | fido 2:507/414.20 |