Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #41834 > unrolled thread
| Started by | Marcos Cruz <null_email_so_use_my_contact_page@programandala.net> |
|---|---|
| First post | 2015-09-07 20:20 +0000 |
| Last post | 2015-09-10 21:26 -0700 |
| Articles | 9 — 6 participants |
Back to article view | Back to comp.lang.forth
`don't` instead of `?do` Marcos Cruz <null_email_so_use_my_contact_page@programandala.net> - 2015-09-07 20:20 +0000
Re: `don't` instead of `?do` Julian Fondren <julian.fondren@gmail.com> - 2015-09-08 11:32 -0700
Re: `don't` instead of `?do` Coos Haak <chforth@hccnet.nl> - 2015-09-09 00:38 +0200
Re: `don't` instead of `?do` Julian Fondren <julian.fondren@gmail.com> - 2015-09-08 15:52 -0700
Re: `don't` instead of `?do` Coos Haak <chforth@hccnet.nl> - 2015-09-09 00:58 +0200
Re: `don't` instead of `?do` Marcos Cruz <null_email_so_use_my_contact_page@programandala.net> - 2015-09-09 11:53 +0000
Re: `don't` instead of `?do` Mark Wills <markwills1970@gmail.com> - 2015-09-09 08:48 -0700
Re: `don't` instead of `?do` Bernd Paysan <bernd.paysan@gmx.de> - 2015-09-09 20:59 +0200
Re: `don't` instead of `?do` hughaguilar96@gmail.com - 2015-09-10 21:26 -0700
| From | Marcos Cruz <null_email_so_use_my_contact_page@programandala.net> |
|---|---|
| Date | 2015-09-07 20:20 +0000 |
| Subject | `don't` instead of `?do` |
| Message-ID | <mskrip$5ff$1@speranza.aioe.org> |
I still haven't implemented in a Forth of mine, but meanwhile I had this simple idea as an alternative, for do-loop structures that are factored in its own definition: : don't ( n1 n2 -- | n1 n2 ) 2dup = if 2drop unnest unnest then ; : list ( n1 n2 -- ) don't do i . loop ; I like the name `don't`, but I accept suggestions. -- Marcos Cruz http://programandala.net
[toc] | [next] | [standalone]
| From | Julian Fondren <julian.fondren@gmail.com> |
|---|---|
| Date | 2015-09-08 11:32 -0700 |
| Message-ID | <af592592-cf97-453d-bf3b-52f10586f629@googlegroups.com> |
| In reply to | #41834 |
On Monday, September 7, 2015 at 3:20:46 PM UTC-5, Marcos Cruz wrote:
> I still haven't implemented in a Forth of mine, but meanwhile I had this
> simple idea as an alternative, for do-loop structures that are factored
> in its own definition:
>
> : don't ( n1 n2 -- | n1 n2 )
> 2dup = if 2drop unnest unnest then ;
>
> : list ( n1 n2 -- )
> don't do i . loop ;
>
> I like the name `don't`, but I accept suggestions.
unnest ?
: don't ( n n -- )
2dup = if 2drop r>drop r>drop then ;
: list ( n n -- )
don't do i . loop ;
\ complete output: 0 1 2 3 4 5 6 7 8 9
: go 10 0 list cr 5 5 list cr 3 1 list ;
A more common word is ?DO , which does nothing if its
arguments are equal.
: list ( n n -- )
?do i . loop ;
: go 10 0 list cr 5 5 list cr 3 1 list ;
\ interactively:
go 0 1 2 3 4 5 6 7 8 9
1 2 ok
If you mean that UNNEST UNNEST should only cause control
to resume after 5 5 LIST rather than after GO and if your
looping words list LIST always exit after LOOP then DON'T
is just a less versatile clone of ?DO ,which can be used
within a larger word, like
: go ( -- )
10 0 ?do i . loop 5 5 ?do i . loop 3 1 ?do i . loop ;
If you do mean that control should resume after GO ,then
I think this would be rarely useful.
-- Julian
[toc] | [prev] | [next] | [standalone]
| From | Coos Haak <chforth@hccnet.nl> |
|---|---|
| Date | 2015-09-09 00:38 +0200 |
| Message-ID | <jjav3nnde0ko$.zrm8qaxewq6i.dlg@40tude.net> |
| In reply to | #41855 |
Op Tue, 8 Sep 2015 11:32:41 -0700 (PDT) schreef Julian Fondren: > On Monday, September 7, 2015 at 3:20:46 PM UTC-5, Marcos Cruz wrote: >> I still haven't implemented in a Forth of mine, but meanwhile I had this >> simple idea as an alternative, for do-loop structures that are factored >> in its own definition: >> >> : don't ( n1 n2 -- | n1 n2 ) >> 2dup = if 2drop unnest unnest then ; >> >> : list ( n1 n2 -- ) >> don't do i . loop ; >> >> I like the name `don't`, but I accept suggestions. > > unnest ? > > : don't ( n n -- ) > 2dup = if 2drop r>drop r>drop then ; > > : list ( n n -- ) > don't do i . loop ; > > \ complete output: 0 1 2 3 4 5 6 7 8 9 > : go 10 0 list cr 5 5 list cr 3 1 list ; > > A more common word is ?DO , which does nothing if its > arguments are equal. > > : list ( n n -- ) > ?do i . loop ; > > : go 10 0 list cr 5 5 list cr 3 1 list ; > > \ interactively: > go 0 1 2 3 4 5 6 7 8 9 > > 1 2 ok > > If you mean that UNNEST UNNEST should only cause control > to resume after 5 5 LIST rather than after GO and if your > looping words list LIST always exit after LOOP then DON'T > is just a less versatile clone of ?DO ,which can be used > within a larger word, like > > : go ( -- ) > 10 0 ?do i . loop 5 5 ?do i . loop 3 1 ?do i . loop ; > > If you do mean that control should resume after GO ,then > I think this would be rarely useful. > > > -- Julian 6.1.2380 UNLOOP CORE Interpretation: Interpretation semantics for this word are undefined. Execution: ( -- ) ( R: loop-sys -- ) Discard the loop-control parameters for the current nesting level. An UNLOOP is required for each nesting level before the definition may be EXITed. An ambiguous condition exists if the loop-control parameters are unavailable. groet Coos
[toc] | [prev] | [next] | [standalone]
| From | Julian Fondren <julian.fondren@gmail.com> |
|---|---|
| Date | 2015-09-08 15:52 -0700 |
| Message-ID | <5f4ad9a0-f776-41bd-aaf7-5c38df15c99b@googlegroups.com> |
| In reply to | #41864 |
On Tuesday, September 8, 2015 at 5:38:57 PM UTC-5, Coos Haak wrote: > 6.1.2380 UNLOOP > CORE What does this have to do what has been said so far? DON'T and ?DO don't exit from a loop. They refuse to enter a loop.
[toc] | [prev] | [next] | [standalone]
| From | Coos Haak <chforth@hccnet.nl> |
|---|---|
| Date | 2015-09-09 00:58 +0200 |
| Message-ID | <5q2fqt4b0gd1.13eocuqm7tkp4$.dlg@40tude.net> |
| In reply to | #41865 |
Op Tue, 8 Sep 2015 15:52:32 -0700 (PDT) schreef Julian Fondren: > On Tuesday, September 8, 2015 at 5:38:57 PM UTC-5, Coos Haak wrote: >> 6.1.2380 UNLOOP >> CORE > > What does this have to do what has been said so far? > > DON'T and ?DO don't exit from a loop. They refuse to > enter a loop. My bad. Didn't read your whole message. Groet Coos
[toc] | [prev] | [next] | [standalone]
| From | Marcos Cruz <null_email_so_use_my_contact_page@programandala.net> |
|---|---|
| Date | 2015-09-09 11:53 +0000 |
| Message-ID | <msp6iu$fcs$1@speranza.aioe.org> |
| In reply to | #41855 |
En/Je/On 2015-09-08, Julian Fondren <julian.fondren@gmail.com> escribió/skribis/wrote: > On Monday, September 7, 2015 at 3:20:46 PM UTC-5, Marcos Cruz wrote: >> : don't ( n1 n2 -- | n1 n2 ) >> 2dup = if 2drop unnest unnest then ; > unnest ? > > : don't ( n n -- ) > 2dup = if 2drop r>drop r>drop then ; Right, `unnest` does `rdrop` (or `r>drop` in your case). > A more common word is ?DO , which does nothing if its arguments are > equal. > then DON'T is just a less versatile clone of ?DO ,which can be used > within a larger word Of course, I know. `don't` is *a simple alternative I wrote while I implement `?do`*, and only useful when the loop is in its own word, not in larger words, as you point out. I think my intention was not clear because, by mistake, the word `?do` was missing from the first sentence of my message: "I still haven't implemented `?do` in a Forth of mine." Regards, -- Marcos Cruz http://programandala.net
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <markwills1970@gmail.com> |
|---|---|
| Date | 2015-09-09 08:48 -0700 |
| Message-ID | <8e5de78d-d150-48d1-9d4a-fc1f679b0987@googlegroups.com> |
| In reply to | #41893 |
Just my two cents: with factoring you don't need don't. Put your loop in its own word and in the calling word use if...then
[toc] | [prev] | [next] | [standalone]
| From | Bernd Paysan <bernd.paysan@gmx.de> |
|---|---|
| Date | 2015-09-09 20:59 +0200 |
| Message-ID | <mspvea$7ia$1@dont-email.me> |
| In reply to | #41897 |
Mark Wills wrote: > Just my two cents: with factoring you don't need don't. Put your loop in > its own word and in the calling word use if...then Well, you can use IF THEN around the DO, too, ?DO just combines both. When you do such factoring, you leave a word which reacts wrong on e.g. the empty string. That's bad. All words e.g. dealing with strings should be fine with the empty string. If these words process the string char-by-char, they usually do bounds ?do .. loop and thus work perfectly with the empty string. Factoring out this check and leaving it to the caller simply is wrong. -- Bernd Paysan "If you want it done right, you have to do it yourself" net2o ID: kQusJzA;7*?t=uy@X}1GWr!+0qqp_Cn176t4(dQ* http://bernd-paysan.de/
[toc] | [prev] | [next] | [standalone]
| From | hughaguilar96@gmail.com |
|---|---|
| Date | 2015-09-10 21:26 -0700 |
| Message-ID | <c417cc95-6f03-497e-93a1-a14ee95842fa@googlegroups.com> |
| In reply to | #41900 |
On Wednesday, September 9, 2015 at 11:59:07 AM UTC-7, Bernd Paysan wrote: > Mark Wills wrote: > > Just my two cents: with factoring you don't need don't. Put your loop in > > its own word and in the calling word use if...then > > Well, you can use IF THEN around the DO, too, ?DO just combines both. > > When you do such factoring, you leave a word which reacts wrong on e.g. the > empty string. That's bad. All words e.g. dealing with strings should be > fine with the empty string. If these words process the string char-by-char, > they usually do > > bounds ?do .. loop > > and thus work perfectly with the empty string. Factoring out this check and > leaving it to the caller simply is wrong. Bernd is right about this --- sooner or later somebody will use the factored out word with the loop (reuse of words is a big part of why they get factored out) and it will fail because it isn't doing error checking --- not all factoring is good...
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.forth
csiph-web