Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Helmar Wodtke Newsgroups: comp.lang.forth Subject: Re: DO... LOOP question Date: Tue, 27 Mar 2012 09:19:21 -0700 (PDT) Organization: http://groups.google.com Lines: 86 Message-ID: <7536008.1597.1332865161513.JavaMail.geo-discussion-forums@vbvd13> References: <10ac1de5-8bd4-4a05-9331-0bdc0c75cd94@x10g2000pbi.googlegroups.com> <5Z-dnYWjobaqGO3SnZ2dnUVZ_sidnZ2d@supernews.com> <13266921.297.1332848048066.JavaMail.geo-discussion-forums@ynel5> <1alsijjhczcmc.r5s3o0lve6ot$.dlg@40tude.net> NNTP-Posting-Host: 62.158.126.42 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1332865278 1163 127.0.0.1 (27 Mar 2012 16:21:18 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 27 Mar 2012 16:21:18 +0000 (UTC) In-Reply-To: <1alsijjhczcmc.r5s3o0lve6ot$.dlg@40tude.net> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=62.158.126.42; posting-account=nibe3QoAAADcYL8fC0WC6vCas4By1Xgn User-Agent: G2/1.0 X-Received-Bytes: 4225 Xref: csiph.com comp.lang.forth:10590 Am Dienstag, 27. M=E4rz 2012 17:33:43 UTC+2 schrieb Coos Haak: > Op Tue, 27 Mar 2012 04:34:07 -0700 (PDT) schreef Helmar Wodtke: >=20 > > Am Dienstag, 27. M=E4rz 2012 13:21:43 UTC+2 schrieb Albert van der Hors= t: > >=20 > >> ... something about WHILE ... > >=20 > > In this case the Forth has to support multiple WHILEs for one loop. > > Difference at the moment between using WHILE and LEAVE is that WHILE ca= n be there one time and LEAVE can be there multiple times. > >=20 > Nope, you can use WHILE multiple times. But you have to add UNLOOP in eve= ry > ELSE part: >=20 > .. DO .. WHILE .. WHILE .. LOOP .. ELSE UNLOOP THEN ELSE UNLOOP THEN .. >=20 > But this is much simpler, and according to the standard. > .. DO .. IF LEAVE THEN .. IF LEAVE THEN .. LOOP >=20 > Or with an other word, ?LEAVE > : ?LEAVE POSTPONE IF POSTPONE LEAVE POSTPONE THEN ; IMMEDIATE > .. DO .. ?LEAVE .. ?LEAVE .. LOOP >=20 > --=20 > Coos >=20 > CHForth, 16 bit DOS applications > http://home.hccnet.nl/j.j.haak/forth.html Oh, what a messy thing. My non-ANS-part works in a way where WHILE is possible multiple times. It all looks simply like this: purpose: implement loop constructs status: mature : do` (loop-push)` begin` ; : (?do) 2dup` (loop-push)` <>` ; : ?do` (?do) if` begin` (while) ; : loop` (loop)` repeat` unloop` ; : +loop` (+loop)` repeat` unloop` ; : leave` ahead` (while) ; : until` 0=3D` while` repeat` ; : while:` begin` ?dup` while` ; : for` while:` 1-` >r` ; : next` r>` repeat` ; : recurse` body compile ; You see some (xxx)-words, that implement some "primitves" - "while" is basi= cally a primitive too. The ANS layer implements it inside this block: {~ Fix 256 buffer pad : begin` seal there ; : while` if` swap ; : while:` begin` ?dup` while` ; : until` 0=3D` while` : repeat` back then` ; : ans-: smudge ::` current-xt ! is-immediate off parse-name current-name place ; : ans-;` seal ;` smudge ; : ans-immediate current-xt @ if is-immediate on ;then immediate ; : exit` seal ;;` ; : ans-recurse` current-xt @ ?dup if compile ;then recurse` ; : key (key) if c@ ;then EOF ; : execute 321 ; /pad buffer pad ~} Main problem with ANS was, that it does not allow the WHILE to be multiple = times - it's not very good, what it takes as implementation predictions the= re... Otherwise WHILE could be doubled without problem. You see that WHILE is implemented in ANS layer basically as: : WHILE POSTPONE IF SWAP ; IMMEDIATE (well, "POSTPONE" is not the right word in all cases...) About that "SWAP" you can think of a long time, but it's on "compilation st= ack"... All that CS-things. Regards, -Helmar