Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #10590
| From | Helmar Wodtke <helmwo@gmail.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: DO... LOOP question |
| Date | 2012-03-27 09:19 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <7536008.1597.1332865161513.JavaMail.geo-discussion-forums@vbvd13> (permalink) |
| References | (2 earlier) <5Z-dnYWjobaqGO3SnZ2dnUVZ_sidnZ2d@supernews.com> <b064493f-2ca9-4845-a1e2-95c75834fc91@pd5g2000pbc.googlegroups.com> <m1jjk7.mrn@spenarnc.xs4all.nl> <13266921.297.1332848048066.JavaMail.geo-discussion-forums@ynel5> <1alsijjhczcmc.r5s3o0lve6ot$.dlg@40tude.net> |
Am Dienstag, 27. März 2012 17:33:43 UTC+2 schrieb Coos Haak:
> Op Tue, 27 Mar 2012 04:34:07 -0700 (PDT) schreef Helmar Wodtke:
>
> > Am Dienstag, 27. März 2012 13:21:43 UTC+2 schrieb Albert van der Horst:
> >
> >> ... something about WHILE ...
> >
> > 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 can be there one time and LEAVE can be there multiple times.
> >
> Nope, you can use WHILE multiple times. But you have to add UNLOOP in every
> ELSE part:
>
> .. DO .. WHILE .. WHILE .. LOOP .. ELSE UNLOOP THEN ELSE UNLOOP THEN ..
>
> But this is much simpler, and according to the standard.
> .. DO .. IF LEAVE THEN .. IF LEAVE THEN .. LOOP
>
> Or with an other word, ?LEAVE
> : ?LEAVE POSTPONE IF POSTPONE LEAVE POSTPONE THEN ; IMMEDIATE
> .. DO .. ?LEAVE .. ?LEAVE .. LOOP
>
> --
> Coos
>
> 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=` 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 basically 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=` 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 <private-state exec private-state> ;
/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 there... 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 stack"... All that CS-things.
Regards,
-Helmar
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
DO... LOOP question Arnold Doray <invalid@invalid.com> - 2012-03-18 15:52 +0000
Re: DO... LOOP question Coos Haak <chforth@hccnet.nl> - 2012-03-18 17:08 +0100
Re: DO... LOOP question BruceMcF <agila61@netscape.net> - 2012-03-18 09:41 -0700
Re: DO... LOOP question Coos Haak <chforth@hccnet.nl> - 2012-03-18 20:51 +0100
Re: DO... LOOP question BruceMcF <agila61@netscape.net> - 2012-03-18 14:37 -0700
Re: DO... LOOP question BruceMcF <agila61@netscape.net> - 2012-03-18 15:56 -0700
Re: DO... LOOP question Coos Haak <chforth@hccnet.nl> - 2012-03-19 01:04 +0100
Re: DO... LOOP question BruceMcF <agila61@netscape.net> - 2012-03-18 17:25 -0700
Re: DO... LOOP question BruceMcF <agila61@netscape.net> - 2012-03-18 17:43 -0700
Re: DO... LOOP question BruceMcF <agila61@netscape.net> - 2012-03-18 18:48 -0700
Re: DO... LOOP question BruceMcF <agila61@netscape.net> - 2012-03-18 21:49 -0700
Re: DO... LOOP question BruceMcF <agila61@netscape.net> - 2012-03-19 11:39 -0700
Re: DO... LOOP question BruceMcF <agila61@netscape.net> - 2012-03-20 12:16 -0700
Re: DO... LOOP question Arnold Doray <invalid@invalid.com> - 2012-03-20 16:54 +0000
Re: DO... LOOP question BruceMcF <agila61@netscape.net> - 2012-03-20 11:41 -0700
Re: DO... LOOP question Arnold Doray <invalid@invalid.com> - 2012-03-24 17:29 +0000
Re: DO... LOOP question Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-03-24 13:22 -0500
Re: DO... LOOP question Arnold Doray <invalid@invalid.com> - 2012-03-25 04:09 +0000
Re: DO... LOOP question Coos Haak <chforth@hccnet.nl> - 2012-03-25 13:49 +0200
Re: DO... LOOP question Arnold Doray <invalid@invalid.com> - 2012-03-27 17:47 +0000
Re: DO... LOOP question Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-03-25 19:45 +0000
Re: DO... LOOP question Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-03-26 04:26 -0500
Re: DO... LOOP question BruceMcF <agila61@netscape.net> - 2012-03-26 07:28 -0700
Re: DO... LOOP question Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-03-26 10:03 -0500
Re: DO... LOOP question Coos Haak <chforth@hccnet.nl> - 2012-03-26 18:47 +0200
Re: DO... LOOP question BruceMcF <agila61@netscape.net> - 2012-03-26 09:53 -0700
Re: DO... LOOP question Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-03-27 11:21 +0000
Re: DO... LOOP question Helmar Wodtke <helmwo@gmail.com> - 2012-03-27 04:34 -0700
Re: DO... LOOP question Coos Haak <chforth@hccnet.nl> - 2012-03-27 17:33 +0200
Re: DO... LOOP question Helmar Wodtke <helmwo@gmail.com> - 2012-03-27 09:19 -0700
Re: DO... LOOP question BruceMcF <agila61@netscape.net> - 2012-03-27 12:20 -0700
Re: DO... LOOP question "Elizabeth D. Rather" <erather@forth.com> - 2012-03-27 09:34 -1000
Re: DO... LOOP question BruceMcF <agila61@netscape.net> - 2012-03-27 13:00 -0700
Re: DO... LOOP question Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-03-26 20:16 -0700
Re: DO... LOOP question BruceMcF <agila61@netscape.net> - 2012-03-24 11:37 -0700
Re: DO... LOOP question Arnold Doray <invalid@invalid.com> - 2012-03-25 06:39 +0000
Re: DO... LOOP question BruceMcF <agila61@netscape.net> - 2012-03-25 06:19 -0700
Re: DO... LOOP question "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2012-03-21 05:48 -0400
Re: DO... LOOP question BruceMcF <agila61@netscape.net> - 2012-03-21 08:36 -0700
Re: DO... LOOP question BruceMcF <agila61@netscape.net> - 2012-03-21 11:24 -0700
Re: DO... LOOP question Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-03-21 03:01 -0700
Re: DO... LOOP question Arnold Doray <invalid@invalid.com> - 2012-03-24 17:44 +0000
Re: DO... LOOP question Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-03-25 11:57 +0000
Re: DO... LOOP question Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-03-26 20:14 -0700
Re: DO... LOOP question Arnold Doray <invalid@invalid.com> - 2012-03-27 16:46 +0000
csiph-web