Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!ai-lab!rice-chex!bson From: bson@rice-chex.ai.mit.edu (Jan Brittenson) Newsgroups: comp.sys.handhelds Subject: Re: CLEAR-TO-MARK code Message-ID: <13117@life.ai.mit.edu> Date: 1 Feb 91 08:40:36 GMT References: Sender: news@ai.mit.edu Organization: nil Lines: 68 In a posting of [29 Jan 91 05:30:00 GMT] TNAN0@CCVAX.IASTATE.EDU writes: > Ok, here's one peraino... > > << DO RAND UNTIL DUP .999 > END >> > > Assume all values are needed until completion of the program (let's > say they would be used in the event that the last value was exactly I'm not sure exactly what I'm arguing and why, but hey... This wouldn't work, as you wouldn't have any idea how many random numbers you had left on the stack. Not without a counter, in which case you know how many to drop if you decide not to use them. To illustrate my point, assume that at the beginning the stack looks like this - am I the only one to prefer the good ol' FIX 4? :-) 3: "ABC" 2: 0.1000 1: 0.4711 Further assume that after the loop above exits, the stack looks like this: 7: "ABC" 6: 0.1000 5: 0.4711 4: 0.rand 3: 0.rand 2: 0.rand 1: 0.9990 A counter is need, and one way is to keep it on top of the stack: << 0 DO 1 + RAND SWAP UNTIL OVER .999 >= END >> Thus you would be left with: 8: "ABC" 7: 0.1000 6: 0.4711 5: 0.rand 4: 0.rand 3: 0.rand 2: 0.9990 1: 4.0000 Then we're compatible with DROPN, ->ARR, ->LIST, etc. You can also feed it to a program: << -> Nelem << 1 Nelem START GOBBLE NEXT >> >> I'm not saying CLEAR is _never_ necessary... just that it sort of defeats the purpose of a stack to clear it. -- Jan Brittenson bson@ai.mit.edu ;; "Make sure the brain is connected before the mouth is started."