Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #44558 > unrolled thread
| Started by | Julian Fondren <julian.fondren@gmail.com> |
|---|---|
| First post | 2016-01-04 14:50 -0800 |
| Last post | 2016-01-08 03:04 -0800 |
| Articles | 20 on this page of 100 — 18 participants |
Back to article view | Back to comp.lang.forth
BEGIN WHILE UNTIL THEN Julian Fondren <julian.fondren@gmail.com> - 2016-01-04 14:50 -0800
Re: BEGIN WHILE UNTIL THEN "HAA" <someone@microsoft.com> - 2016-01-05 11:24 +1100
Re: BEGIN WHILE UNTIL THEN Julian Fondren <julian.fondren@gmail.com> - 2016-01-04 16:47 -0800
Re: BEGIN WHILE UNTIL THEN "HAA" <someone@microsoft.com> - 2016-01-05 12:17 +1100
Re: BEGIN WHILE UNTIL THEN anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-05 10:51 +0000
Re: BEGIN WHILE UNTIL THEN stephen@mpeforth.com (Stephen Pelc) - 2016-01-05 15:06 +0000
Re: BEGIN WHILE UNTIL THEN Chris Curl <ccurl609@gmail.com> - 2016-01-04 17:25 -0800
Re: BEGIN WHILE UNTIL THEN "HAA" <someone@microsoft.com> - 2016-01-05 13:06 +1100
Re: BEGIN WHILE UNTIL THEN Chris Curl <ccurl609@gmail.com> - 2016-01-04 21:42 -0800
Re: BEGIN WHILE UNTIL THEN rickman <gnuarm@gmail.com> - 2016-01-05 01:48 -0500
Re: BEGIN WHILE UNTIL THEN Albert van der Horst <albert@spenarnc.xs4all.nl> - 2016-01-05 11:15 +0000
Re: BEGIN WHILE UNTIL THEN "HAA" <someone@microsoft.com> - 2016-01-06 14:35 +1100
Re: BEGIN WHILE UNTIL THEN Albert van der Horst <albert@spenarnc.xs4all.nl> - 2016-01-05 02:04 +0000
Re: BEGIN WHILE UNTIL THEN Julian Fondren <julian.fondren@gmail.com> - 2016-01-04 18:37 -0800
Re: BEGIN WHILE UNTIL THEN hughaguilar96@gmail.com - 2016-01-04 19:17 -0800
Re: BEGIN WHILE UNTIL THEN anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-05 11:10 +0000
Re: BEGIN WHILE UNTIL THEN "HAA" <someone@microsoft.com> - 2016-01-06 15:02 +1100
Re: BEGIN WHILE UNTIL THEN november.nihal@gmail.com - 2016-01-05 08:03 -0800
Re: BEGIN WHILE UNTIL THEN november.nihal@gmail.com - 2016-01-05 08:07 -0800
Re: BEGIN WHILE UNTIL THEN november.nihal@gmail.com - 2016-01-05 08:18 -0800
Re: BEGIN WHILE UNTIL THEN november.nihal@gmail.com - 2016-01-05 08:21 -0800
Re: BEGIN WHILE UNTIL THEN Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-01-07 05:13 -0500
Re: BEGIN WHILE UNTIL THEN "HAA" <someone@microsoft.com> - 2016-01-08 12:36 +1100
Re: BEGIN WHILE UNTIL THEN anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-08 10:32 +0000
Re: BEGIN WHILE UNTIL THEN Raimond Dragomir <raimond.dragomir@gmail.com> - 2016-01-08 02:55 -0800
Re: BEGIN WHILE UNTIL THEN Coos Haak <chforth@hccnet.nl> - 2016-01-08 13:57 +0100
Re: BEGIN WHILE UNTIL THEN Raimond Dragomir <raimond.dragomir@gmail.com> - 2016-01-08 06:55 -0800
Re: BEGIN WHILE UNTIL THEN hughaguilar96@gmail.com - 2016-01-08 15:06 -0800
Re: BEGIN WHILE UNTIL THEN Chris Curl <ccurl609@gmail.com> - 2016-01-08 16:59 -0800
Re: BEGIN WHILE UNTIL THEN "Elizabeth D. Rather" <erather@forth.com> - 2016-01-08 16:15 -1000
Re: BEGIN WHILE UNTIL THEN Chris Curl <ccurl609@gmail.com> - 2016-01-08 22:23 -0800
Re: BEGIN WHILE UNTIL THEN "Elizabeth D. Rather" <erather@forth.com> - 2016-01-08 21:12 -1000
Re: BEGIN WHILE UNTIL THEN Chris Curl <ccurl609@gmail.com> - 2016-01-09 08:04 -0800
Re: BEGIN WHILE UNTIL THEN "Elizabeth D. Rather" <erather@forth.com> - 2016-01-09 09:16 -1000
Re: BEGIN WHILE UNTIL THEN anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-10 15:31 +0000
Re: BEGIN WHILE UNTIL THEN Chris Curl <ccurl609@gmail.com> - 2016-01-10 08:11 -0800
Re: BEGIN WHILE UNTIL THEN "Elizabeth D. Rather" <erather@forth.com> - 2016-01-10 09:42 -1000
Re: BEGIN WHILE UNTIL THEN Albert van der Horst <albert@spenarnc.xs4all.nl> - 2016-01-11 13:02 +0000
Re: BEGIN WHILE UNTIL THEN anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-13 16:20 +0000
Re: BEGIN WHILE UNTIL THEN hughaguilar96@gmail.com - 2016-01-10 14:10 -0800
Re: BEGIN WHILE UNTIL THEN hughaguilar96@gmail.com - 2016-01-11 18:38 -0800
Re: BEGIN WHILE UNTIL THEN "HAA" <someone@microsoft.com> - 2016-01-14 08:47 +1100
Re: BEGIN WHILE UNTIL THEN Chris Curl <ccurl609@gmail.com> - 2016-01-13 17:24 -0800
Re: BEGIN WHILE UNTIL THEN hughaguilar96@gmail.com - 2016-01-13 19:25 -0800
Re: BEGIN WHILE UNTIL THEN "HAA" <someone@microsoft.com> - 2016-01-14 22:09 +1100
Re: BEGIN WHILE UNTIL THEN anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-14 16:21 +0000
Re: BEGIN WHILE UNTIL THEN "HAA" <someone@microsoft.com> - 2016-01-16 11:34 +1100
Re: BEGIN WHILE UNTIL THEN Bernd Paysan <bernd.paysan@gmx.de> - 2016-01-16 03:43 +0100
Re: BEGIN WHILE UNTIL THEN "HAA" <someone@microsoft.com> - 2016-01-19 18:01 +1100
Re: BEGIN WHILE UNTIL THEN Bernd Paysan <bernd.paysan@gmx.de> - 2016-01-19 23:07 +0100
Re: BEGIN WHILE UNTIL THEN "HAA" <someone@microsoft.com> - 2016-01-21 14:29 +1100
Re: BEGIN WHILE UNTIL THEN Bernd Paysan <bernd.paysan@gmx.de> - 2016-01-21 22:25 +0100
Re: BEGIN WHILE UNTIL THEN "HAA" <someone@microsoft.com> - 2016-01-24 13:28 +1100
Re: BEGIN WHILE UNTIL THEN Bernd Paysan <bernd.paysan@gmx.de> - 2016-01-25 01:31 +0100
Re: BEGIN WHILE UNTIL THEN "HAA" <someone@microsoft.com> - 2016-01-25 21:45 +1100
Re: BEGIN WHILE UNTIL THEN Chris Curl <ccurl609@gmail.com> - 2016-01-25 10:24 -0800
Re: BEGIN WHILE UNTIL THEN Bernd Paysan <bernd.paysan@gmx.de> - 2016-01-25 20:41 +0100
Re: BEGIN WHILE UNTIL THEN "HAA" <someone@microsoft.com> - 2016-01-28 20:39 +1100
Re: BEGIN WHILE UNTIL THEN Bernd Paysan <bernd.paysan@gmx.de> - 2016-01-28 16:05 +0100
Re: BEGIN WHILE UNTIL THEN Chris Curl <ccurl609@gmail.com> - 2016-01-21 20:52 -0800
Re: BEGIN WHILE UNTIL THEN "HAA" <someone@microsoft.com> - 2016-01-24 13:16 +1100
Re: BEGIN WHILE UNTIL THEN Chris Curl <ccurl609@gmail.com> - 2016-01-14 08:46 -0800
Re: BEGIN WHILE UNTIL THEN "HAA" <someone@microsoft.com> - 2016-01-16 11:34 +1100
Re: BEGIN WHILE UNTIL THEN Chris Curl <ccurl609@gmail.com> - 2016-01-15 20:53 -0800
Re: BEGIN WHILE UNTIL THEN hughaguilar96@gmail.com - 2016-01-13 19:31 -0800
Re: BEGIN WHILE UNTIL THEN "HAA" <someone@microsoft.com> - 2016-01-11 09:29 +1100
Re: BEGIN WHILE UNTIL THEN Chris Curl <ccurl609@gmail.com> - 2016-01-10 21:18 -0800
Re: BEGIN WHILE UNTIL THEN Paul Rubin <no.email@nospam.invalid> - 2016-01-10 21:29 -0800
Re: BEGIN WHILE UNTIL THEN "Elizabeth D. Rather" <erather@forth.com> - 2016-01-10 20:37 -1000
Re: BEGIN WHILE UNTIL THEN Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-01-11 09:05 +0000
Re: BEGIN WHILE UNTIL THEN "HAA" <someone@microsoft.com> - 2016-01-12 12:26 +1100
Re: BEGIN WHILE UNTIL THEN hughaguilar96@gmail.com - 2016-01-10 14:18 -0800
Re: BEGIN WHILE UNTIL THEN Raimond Dragomir <raimond.dragomir@gmail.com> - 2016-01-08 23:31 -0800
Re: BEGIN WHILE UNTIL THEN Chris Curl <ccurl609@gmail.com> - 2016-01-09 08:09 -0800
Re: BEGIN WHILE UNTIL THEN Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-01-09 05:31 -0600
Re: BEGIN WHILE UNTIL THEN Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-01-09 07:52 -0600
Re: BEGIN WHILE UNTIL THEN Ron Aaron <rambamist@gmail.com> - 2016-01-09 18:22 +0200
Re: BEGIN WHILE UNTIL THEN anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-09 16:29 +0000
Re: BEGIN WHILE UNTIL THEN stephen@mpeforth.com (Stephen Pelc) - 2016-01-08 11:23 +0000
Re: BEGIN WHILE UNTIL THEN hughaguilar96@gmail.com - 2016-01-10 20:17 -0800
Re: BEGIN WHILE UNTIL THEN stephen@mpeforth.com (Stephen Pelc) - 2016-01-11 11:56 +0000
Re: BEGIN WHILE UNTIL THEN Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-01-11 11:59 +0000
generalized CASE (was: BEGIN WHILE UNTIL THEN) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-11 12:30 +0000
Re: generalized CASE (was: BEGIN WHILE UNTIL THEN) hughaguilar96@gmail.com - 2016-01-11 13:52 -0800
Re: generalized CASE Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-01-11 22:00 +0000
Re: generalized CASE Coos Haak <chforth@hccnet.nl> - 2016-01-12 01:50 +0100
Re: BEGIN WHILE UNTIL THEN hughaguilar96@gmail.com - 2016-01-11 14:16 -0800
Re: BEGIN WHILE UNTIL THEN Chris Curl <ccurl609@gmail.com> - 2016-01-11 16:17 -0800
Re: BEGIN WHILE UNTIL THEN anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-12 13:07 +0000
Re: BEGIN WHILE UNTIL THEN Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-01-12 20:48 +0000
Re: BEGIN WHILE UNTIL THEN hughaguilar96@gmail.com - 2016-01-12 14:16 -0800
Re: BEGIN WHILE UNTIL THEN anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-08 16:21 +0000
Re: BEGIN WHILE UNTIL THEN stephen@mpeforth.com (Stephen Pelc) - 2016-01-08 20:12 +0000
Re: BEGIN WHILE UNTIL THEN anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-01-09 18:19 +0000
Re: BEGIN WHILE UNTIL THEN "HAA" <someone@microsoft.com> - 2016-01-11 09:34 +1100
Re: BEGIN WHILE UNTIL THEN Bernd Paysan <bernd.paysan@gmx.de> - 2016-01-08 21:13 +0100
Re: BEGIN WHILE UNTIL THEN "HAA" <someone@microsoft.com> - 2016-01-09 23:46 +1100
Re: BEGIN WHILE UNTIL THEN Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-01-08 10:11 -0500
Re: BEGIN WHILE UNTIL THEN "HAA" <someone@microsoft.com> - 2016-01-11 08:38 +1100
Re: BEGIN WHILE UNTIL THEN november.nihal@gmail.com - 2016-01-08 03:04 -0800
Page 1 of 5 [1] 2 3 4 5 Next page →
| From | Julian Fondren <julian.fondren@gmail.com> |
|---|---|
| Date | 2016-01-04 14:50 -0800 |
| Subject | BEGIN WHILE UNTIL THEN |
| Message-ID | <08c4616c-21ad-4bdf-9fe4-a9e5ee2e5dad@googlegroups.com> |
Hello clf,
The following code is from SwoopPortable.f
: UPDATE-LINKS ( super link -- ) >R
BEGIN
DUP @ DUP WHILE \ prev cur
R@ BEGIN \ prev cur sup
@ DUP WHILE \ prev cur sup'
2DUP = UNTIL
2DROP R> @ SWAP ! EXIT
THEN DROP NIP
REPEAT R> DROP 2DROP ;
Can someone rewrite this with normal control-flow?
Thanks,
Julian
[toc] | [next] | [standalone]
| From | "HAA" <someone@microsoft.com> |
|---|---|
| Date | 2016-01-05 11:24 +1100 |
| Message-ID | <n6f2bj$qgs$1@gioia.aioe.org> |
| In reply to | #44558 |
Julian Fondren wrote: > Hello clf, > > The following code is from SwoopPortable.f > ... > Can someone rewrite this with normal control-flow? By 'normal' you mean pre Forth-94? You don't say why you need such a thing. It matters because the result will likely be longer less efficient code.
[toc] | [prev] | [next] | [standalone]
| From | Julian Fondren <julian.fondren@gmail.com> |
|---|---|
| Date | 2016-01-04 16:47 -0800 |
| Message-ID | <70db56dd-4768-4b8d-b94d-fb3200806866@googlegroups.com> |
| In reply to | #44561 |
On Monday, January 4, 2016 at 6:24:21 PM UTC-6, HAA wrote:
> Julian Fondren wrote:
> > Hello clf,
> >
> > The following code is from SwoopPortable.f
> > ...
> > Can someone rewrite this with normal control-flow?
>
> By 'normal' you mean pre Forth-94? You don't say why you need such a
> thing. It matters because the result will likely be longer less efficient code.
By normal I mean, not requiring me to drop the pretense of
structured programming, not requiring me to interpret these
words as just performing conditional and unconditional GOTOs.
Personally, the benefits to this kind of programming aren't
worth it. It's too hard to understand. It abuses the *names*
of words. THEN isn't THEN, really; it's just "resolve last
forward branch". I'd rather just have numbers in my code, like
I think one of Rick Hohensee's Forths:
: stars ( n -- )
dup 0>= ?->(0) ." I don't how to display negative stars" abort
(0) dup 0= ?->(1) 1- ." *" ->(0)
(1) drop ;
(n) is a branch target.
->(n) branches to it.
?->(n) conditionally branches to it.
Ugly? At least it does what it says, and no different.
Anyway, the SwoopPortable.f version breaks under ciforth.
ciforth's THEN complains at compile-time about control flow
balance, and if that error is neutralized, it just miscompiles
the definition and fails at runtime.
(I'm aware that there are *many* other ways in which ciforth
can't handle SwoopPortable.f. I bridged many of those gaps to
come to this point.)
-- Julian
[toc] | [prev] | [next] | [standalone]
| From | "HAA" <someone@microsoft.com> |
|---|---|
| Date | 2016-01-05 12:17 +1100 |
| Message-ID | <n6f5f5$usl$1@gioia.aioe.org> |
| In reply to | #44562 |
Julian Fondren wrote:
> On Monday, January 4, 2016 at 6:24:21 PM UTC-6, HAA wrote:
> > Julian Fondren wrote:
> > > Hello clf,
> > >
> > > The following code is from SwoopPortable.f
> > > ...
> > > Can someone rewrite this with normal control-flow?
> >
> > By 'normal' you mean pre Forth-94? You don't say why you need such a
> > thing. It matters because the result will likely be longer less efficient code.
>
> By normal I mean, not requiring me to drop the pretense of
> structured programming, not requiring me to interpret these
> words as just performing conditional and unconditional GOTOs.
It's all GOTOs 'under the hood' :)
>
> Personally, the benefits to this kind of programming aren't
> worth it. It's too hard to understand. It abuses the *names*
> of words. THEN isn't THEN, really; it's just "resolve last
> forward branch". I'd rather just have numbers in my code, like
> I think one of Rick Hohensee's Forths:
>
> : stars ( n -- )
> dup 0>= ?->(0) ." I don't how to display negative stars" abort
> (0) dup 0= ?->(1) 1- ." *" ->(0)
> (1) drop ;
>
> (n) is a branch target.
> ->(n) branches to it.
> ?->(n) conditionally branches to it.
>
> Ugly? At least it does what it says, and no different.
>
> Anyway, the SwoopPortable.f version breaks under ciforth.
> ciforth's THEN complains at compile-time about control flow
> balance, and if that error is neutralized, it just miscompiles
> the definition and fails at runtime.
It's trivial for implementers to make WHILE Forth-94 compatible
even they choose not to use it.
> (I'm aware that there are *many* other ways in which ciforth
> can't handle SwoopPortable.f. I bridged many of those gaps to
> come to this point.)
Try this (untested)
: UPDATE-LINKS ( super link -- )
>R BEGIN
DUP @ DUP
WHILE \ prev cur
R@ BEGIN \ prev cur sup
@ DUP
WHILE \ prev cur sup'
2DUP = IF 2DROP R> @ SWAP ! EXIT THEN
REPEAT DROP NIP
REPEAT R> DROP 2DROP ;
VFX reports 96 bytes, 37 instructions compared with 90 bytes, 36 instructions
for the original. So not much difference in this case (one extra jump).
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2016-01-05 10:51 +0000 |
| Message-ID | <2016Jan5.115120@mips.complang.tuwien.ac.at> |
| In reply to | #44562 |
Julian Fondren <julian.fondren@gmail.com> writes:
>By normal I mean, not requiring me to drop the pretense of
>structured programming, not requiring me to interpret these
>words as just performing conditional and unconditional GOTOs.
Actually, if you see this as one structure, it is structured
programming: It has one entrance and one exit.
>Personally, the benefits to this kind of programming aren't
>worth it. It's too hard to understand. It abuses the *names*
>of words. THEN isn't THEN, really; it's just "resolve last
>forward branch".
It's a matter of getting used to. I don't think that doing everything
that's possible (e.g., using ELSE to pair with WHILE) is a good idea,
but if you have multiple exit conditions, multiple WHILEs, or
WHILE...UNTIL are a common pattern. I.e.,
BEGIN ... WHILE ... WHILE ... WHILE ... AGAIN THEN THEN THEN
BEGIN ... WHILE ... WHILE ... WHILE ... UNTIL THEN THEN THEN
with one THEN for each WHILE. I don't consider it a good idea to put
something between the THENs, because then you have to match the THEN
to the WHILE that jumps there. Putting something between UNTIL and
the first then, as in the example does not require matching, so it's
still acceptable.
Of course we have also discussed other options in the past, such as
using EXIT or a generalized CASE, but despite Gforth having a
generalized CASE, I have not used it. The uses are rare enough that I
would have to look up the words when needed; OTOH, the WHILE ... THEN
usage is discussed frequently enough here that I grok it even though I
prefer using EXIT myself.
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2015: http://www.rigwit.co.uk/EuroForth2015/
[toc] | [prev] | [next] | [standalone]
| From | stephen@mpeforth.com (Stephen Pelc) |
|---|---|
| Date | 2016-01-05 15:06 +0000 |
| Message-ID | <568bda7c.1712283416@news.eternal-september.org> |
| In reply to | #44580 |
On Tue, 05 Jan 2016 10:51:20 GMT, anton@mips.complang.tuwien.ac.at
(Anton Ertl) wrote:
>Of course we have also discussed other options in the past, such as
>using EXIT or a generalized CASE, but despite Gforth having a
>generalized CASE, I have not used it. The uses are rare enough that I
>would have to look up the words when needed; OTOH, the WHILE ... THEN
>usage is discussed frequently enough here that I grok it even though I
>prefer using EXIT myself.
Gosh! I agree with Anton. Similarly, VFX has had a generalised
BEGINCASE ... OF ... ENDOF ... NEXTCASE structure for many years
to provide a generalised multi-exit loop with exit actions and
better readability than clever use of other structures.
begincase
of ... endof
of ... endof
of ... endof
nextcase
Over the last decause or so I have not used it. Better factoring
and use of EXIT produces code in better Forth style.
Stephen
--
Stephen Pelc, stephenXXX@mpeforth.com
MicroProcessor Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
web: http://www.mpeforth.com - free VFX Forth downloads
[toc] | [prev] | [next] | [standalone]
| From | Chris Curl <ccurl609@gmail.com> |
|---|---|
| Date | 2016-01-04 17:25 -0800 |
| Message-ID | <d3f8b142-4385-4ea7-9e15-fb1e1dd2cef5@googlegroups.com> |
| In reply to | #44558 |
On Monday, January 4, 2016 at 5:50:26 PM UTC-5, Julian Fondren wrote: > Can someone rewrite this with normal control-flow? > > ... > > Thanks, > Julian Like you, I have a philosophy against THEN without IF. I understand that the behavior may very well be such that it happens to tidy up the same sort of loose end(s) left by IF (ELSE), but using THEN without IF is not at all intuitive.
[toc] | [prev] | [next] | [standalone]
| From | "HAA" <someone@microsoft.com> |
|---|---|
| Date | 2016-01-05 13:06 +1100 |
| Message-ID | <n6f8af$12q6$1@gioia.aioe.org> |
| In reply to | #44564 |
Chris Curl wrote: > On Monday, January 4, 2016 at 5:50:26 PM UTC-5, Julian Fondren wrote: > > Can someone rewrite this with normal control-flow? > > > > ... > > > > Thanks, > > Julian > Like you, I have a philosophy against THEN without IF. I understand > that the behavior may very well be such that it happens to tidy up the > same sort of loose end(s) left by IF (ELSE), but using THEN without IF is > not at all intuitive. 'Forth isn't intuitive' is the most used excuse against learning it. So it is with WHILE. Efficient code generation is the reason you should.
[toc] | [prev] | [next] | [standalone]
| From | Chris Curl <ccurl609@gmail.com> |
|---|---|
| Date | 2016-01-04 21:42 -0800 |
| Message-ID | <71d5ef41-ae68-465e-ad3f-f52664d969f0@googlegroups.com> |
| In reply to | #44565 |
On Monday, January 4, 2016 at 9:06:11 PM UTC-5, HAA wrote: > 'Forth isn't intuitive' is the most used excuse against learning it. So it > is with WHILE. Efficient code generation is the reason you should. Trust me, I understand Forth. It feels like you don't get the power of it. Tell me ... what does THEN do exactly that makes it so "efficient"? Isn't it actually a pretty simple and straightforward construct? Why would it be so difficult to define another word that actually makes sense in context that does exactly the same thing? How is that approach not better in every way?
[toc] | [prev] | [next] | [standalone]
| From | rickman <gnuarm@gmail.com> |
|---|---|
| Date | 2016-01-05 01:48 -0500 |
| Message-ID | <n6foqr$2vs$1@dont-email.me> |
| In reply to | #44571 |
On 1/5/2016 12:42 AM, Chris Curl wrote: > On Monday, January 4, 2016 at 9:06:11 PM UTC-5, HAA wrote: >> 'Forth isn't intuitive' is the most used excuse against learning it. So it >> is with WHILE. Efficient code generation is the reason you should. > Trust me, I understand Forth. It feels like you don't get the power of it. > > Tell me ... what does THEN do exactly that makes it so "efficient"? Isn't > it actually a pretty simple and straightforward construct? Why would it be > so difficult to define another word that actually makes sense in context > that does exactly the same thing? How is that approach not better in every > way? The issue is not what THEN does, the issue is using the various constructs allowed the programmer to create a solution that was mapped very closely to how he saw the problem but at the same time leaving a very tangled mess of flow control. THEN is just the method of matching the destination to the jump that goes there, no magic. But it normally matches with an ELSE or an IF. Matching it with a WHILE that is paired with an UNTIL creates a very odd and complicated flow control. Using more conventional structured programming flow would be more wordy if not more code. As soon as I saw this thread I started converting the flow control to structured programming, but I figured someone else would do it faster and better... so far not. I have some things to do tomorrow. If no one else has posted a structured solution I will give it a go. -- Rick
[toc] | [prev] | [next] | [standalone]
| From | Albert van der Horst <albert@spenarnc.xs4all.nl> |
|---|---|
| Date | 2016-01-05 11:15 +0000 |
| Message-ID | <568ba5dd$0$23861$e4fe514c@news.xs4all.nl> |
| In reply to | #44571 |
Chris Curl <ccurl609@gmail.com> writes: >On Monday, January 4, 2016 at 9:06:11 PM UTC-5, HAA wrote: >> 'Forth isn't intuitive' is the most used excuse against learning it. So it >> is with WHILE. Efficient code generation is the reason you should. >Trust me, I understand Forth. It feels like you don't get the power of it. >Tell me ... what does THEN do exactly that makes it so "efficient"? Isn't >it actually a pretty simple and straightforward construct? Why would it be >so difficult to define another word that actually makes sense in context >that does exactly the same thing? How is that approach not better in every >way? In ciforth I have approximately : IF POSTPONE 0BRANCH (FORWARD ; IMMEDIATE : THEN FORWARD) ; IMMEDIATE In the minds of some people the meaning of THEN -- part of structured construct-- and `` FORWARD) '' -- resolve forward branch -- are merged. The original meaning of THEN , something along " continue here", lends some credibility to it. I prefer to have SECURITY on , because it catches a lot of mistakes. Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
[toc] | [prev] | [next] | [standalone]
| From | "HAA" <someone@microsoft.com> |
|---|---|
| Date | 2016-01-06 14:35 +1100 |
| Message-ID | <n6i21l$1ulh$1@gioia.aioe.org> |
| In reply to | #44571 |
Chris Curl wrote: > On Monday, January 4, 2016 at 9:06:11 PM UTC-5, HAA wrote: > > 'Forth isn't intuitive' is the most used excuse against learning it. So it > > is with WHILE. Efficient code generation is the reason you should. > > Trust me, I understand Forth. It feels like you don't get the power of it. > > Tell me ... what does THEN do exactly that makes it so "efficient"? Isn't > it actually a pretty simple and straightforward construct? Why would it be > so difficult to define another word that actually makes sense in context > that does exactly the same thing? How is that approach not better in every > way? Because it takes more time and code avoiding WHILE than using it.
[toc] | [prev] | [next] | [standalone]
| From | Albert van der Horst <albert@spenarnc.xs4all.nl> |
|---|---|
| Date | 2016-01-05 02:04 +0000 |
| Message-ID | <568b24a6$0$23810$e4fe514c@news.xs4all.nl> |
| In reply to | #44558 |
Julian Fondren <julian.fondren@gmail.com> writes:
>Hello clf,
>The following code is from SwoopPortable.f
> : UPDATE-LINKS ( super link -- ) >R
> BEGIN
> DUP @ DUP WHILE \ prev cur
> R@ BEGIN \ prev cur sup
> @ DUP WHILE \ prev cur sup'
> 2DUP = UNTIL
> 2DROP R> @ SWAP ! EXIT
> THEN DROP NIP
> REPEAT R> DROP 2DROP ;
>Can someone rewrite this with normal control-flow?
NO-SECURITY is foreseen for such code.
If I load it on lina with NO-SECURITY
"
S[ ] OK albert@cherry:/tmp$ lina32 -a
WANT NO-SECURITY
OK
NO-SECURITY
OK
: UPDATE-LINKS ( super link -- ) >R
BEGIN
DUP @ DUP WHILE \ prev cur
R@ BEGIN \ prev cur sup
@ DUP WHILE \ prev cur sup'
2DUP = UNTIL
2DROP R> @ SWAP ! EXIT
THEN DROP NIP
REPEAT R> DROP 2DROP ;
OK
"
it is accepted.
Now I can inspect it, and at least it looks like all branches
end where intended:
"
WANT SEE
OK
SEE UPDATE-LINKS
: UPDATE-LINKS
>R DUP @ DUP
0BRANCH [ 4C , ] ( between ? R> ) R@ @ DUP
0BRANCH [ 28 , ] ( between EXIT DROP ) 2DUP =
0BRANCH [ -20 , ] ( between R@ @ ) 2DROP R> @ SWAP ! EXIT DROP NIP
BRANCH [ -60 , ] ( between >R DUP ) R> DROP 2DROP
;
OK
"
You can use DO-DEBUG and compile the program line by line,
then you can see what the compilation stack (in ciforth: the
data stack at compile time) contains.
It also shows a way out:
Replace the second WHILE with
0BRANCH [ $0A CELLS , ]
and leave out the THEN between EXIT and DROP , like so:
"
: UPDATE-LINKS ( super link -- ) >R
BEGIN
DUP @ DUP WHILE \ prev cur
R@ BEGIN \ prev cur sup
@ DUP 0BRANCH [ HEX 28 , ] \ prev cur sup'
2DUP = UNTIL
2DROP R> @ SWAP ! EXIT
DROP NIP
REPEAT R> DROP 2DROP ;
"
( HEX 28 is for 32 bits ciforth, YMMV).
WARNING: this may not work with the -e option where control
flows words are replaced to work while interpreting.
>Thanks,
>Julian
Groetjes Albert
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
[toc] | [prev] | [next] | [standalone]
| From | Julian Fondren <julian.fondren@gmail.com> |
|---|---|
| Date | 2016-01-04 18:37 -0800 |
| Message-ID | <3db66e3d-3161-456f-8473-805847abee24@googlegroups.com> |
| In reply to | #44558 |
On Monday, January 4, 2016 at 8:06:11 PM UTC-6, HAA wrote: > 'Forth isn't intuitive' is the most used excuse against learning it. So it > is with WHILE. Efficient code generation is the reason you should. If you don't understand FORTH LOVE IF HONK THEN you can read a book, take a class, do some tutorials, and then you'll understand it just fine. You can rely on anyone claiming to know Forth to understand you when you write it. If someone claims to know other languages, but not Forth, you can write similar code in a language they know and say "it works like this". If you don't understand BEGIN WHILE UNTIL THEN you can read a book and then you still won't understand it because it only works by accident. I've defined a lot of words that could be used contrary to their specification and still result in some generated code that does something useful. But who would do that deliberately? That's madness. Well that's what I've done for years with using COUNT to walk through strings rather than just get the length of counted strings them but putting that aside... If you want efficient code generation then come up with words that make sense that generate that code. This THEN-abuse code isn't an argument against Forth by itself, but it is in the context of Forthers tending to think that it's merely clever instead of a horrifyingly unreadable hack. On Monday, January 4, 2016 at 8:15:02 PM UTC-6, Albert van der Horst wrote: > NO-SECURITY is foreseen for such code. Ah, it replaces ?PAIRS with 2DROP. I did that too. I should have searched for ?PAIRS in forth.lab And it turns out that the bug is upstream of UPDATE-LINKS ; it wasn't a case of miscompilation. -- Julian
[toc] | [prev] | [next] | [standalone]
| From | hughaguilar96@gmail.com |
|---|---|
| Date | 2016-01-04 19:17 -0800 |
| Message-ID | <f0e706fd-678d-4f05-b0e7-9232b35b3dd2@googlegroups.com> |
| In reply to | #44567 |
On Monday, January 4, 2016 at 7:37:57 PM UTC-7, Julian Fondren wrote: > If you don't understand BEGIN WHILE UNTIL THEN you > can read a book and then you still won't understand it because it only > works by accident. I've defined a lot of words that could be used > contrary to their specification and still result in some generated > code that does something useful. But who would do that deliberately? > That's madness. I agree that BEGIN WHILE UNTIL THEN is just bizarre. I never saw such a thing before ANS-Forth, and I was astounded that this was considered to be legal code. I don't write code like this. I would put the loop in a function all by itself then use EXIT to get out of the loop. This results in pretty readable code. I don't use CASE either --- once again, put the control structure in a function all by itself and use EXIT to get out. The only problem with this technique is that the function with the loop doesn't have access to the local variables of the calling function. This can be solved however if you have quotations because your loop can be in a quotation and EXIT can be used to get out of the loop, but the quotation still has access to the parent function's local variables. There is a book called: "JavaScript: the Good Parts." Maybe somebody could write a book called: "ANS-Forth: the Good Parts." This book would tell us to not use BEGIN WHILE UNTIL THEN and to not use CASE etc.. Unfortunately, this would be the world's thinnest book --- somewhat comparable to: "Cooking Coyotes: the Good Parts."
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2016-01-05 11:10 +0000 |
| Message-ID | <2016Jan5.121030@mips.complang.tuwien.ac.at> |
| In reply to | #44567 |
Julian Fondren <julian.fondren@gmail.com> writes:
>If you don't understand FORTH LOVE IF HONK THEN you can read a book,
>take a class, do some tutorials, and then you'll understand it just
>fine. You can rely on anyone claiming to know Forth to understand you
>when you write it. If someone claims to know other languages, but not
>Forth, you can write similar code in a language they know and say "it
>works like this". If you don't understand BEGIN WHILE UNTIL THEN you
>can read a book and then you still won't understand it because it only
>works by accident.
No, it works by design; see
<http://www.forth200x.org/documents/html/rationale.html#paragraph.A.3.2.3.2>
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2015: http://www.rigwit.co.uk/EuroForth2015/
[toc] | [prev] | [next] | [standalone]
| From | "HAA" <someone@microsoft.com> |
|---|---|
| Date | 2016-01-06 15:02 +1100 |
| Message-ID | <n6i3lh$fo$1@gioia.aioe.org> |
| In reply to | #44567 |
Julian Fondren wrote: > On Monday, January 4, 2016 at 8:06:11 PM UTC-6, HAA wrote: > > 'Forth isn't intuitive' is the most used excuse against learning it. So it > > is with WHILE. Efficient code generation is the reason you should. > ... > If you want efficient code generation then come up with words that > make sense that generate that code. This THEN-abuse code isn't an > argument against Forth by itself, but it is in the context of Forthers > tending to think that it's merely clever instead of a horrifyingly > unreadable hack. THEN is used to resolve a conditional. It's always been thus in Forth. You can tell yourself THEN should only be used after IF or ELSE but it misses the point and today it just gets in the way.
[toc] | [prev] | [next] | [standalone]
| From | november.nihal@gmail.com |
|---|---|
| Date | 2016-01-05 08:03 -0800 |
| Message-ID | <1b61f097-684d-457e-8911-1036aa9438d6@googlegroups.com> |
| In reply to | #44558 |
On Monday, 4 January 2016 22:50:26 UTC, Julian Fondren wrote: > Hello clf, > > The following code is from SwoopPortable.f > > : UPDATE-LINKS ( super link -- ) >R > BEGIN > DUP @ DUP WHILE \ prev cur > R@ BEGIN \ prev cur sup > @ DUP WHILE \ prev cur sup' > 2DUP = UNTIL > 2DROP R> @ SWAP ! EXIT > THEN DROP NIP > REPEAT R> DROP 2DROP ; > > Can someone rewrite this with normal control-flow? > > > Thanks, > Julian : update-links3 begin @ dup if abort then 2dup = until ; : update-links2 ['] update-links3 catch if drop nip else 2drop r> @ swap ! exit then ; : update-links1 begin dup @ dup while r@ update-links2 repeat ; : update-links ( super link -- ) r> update-links1 r> drop 2drop ;
[toc] | [prev] | [next] | [standalone]
| From | november.nihal@gmail.com |
|---|---|
| Date | 2016-01-05 08:07 -0800 |
| Message-ID | <3fa98cc2-f34f-40b4-95a4-fa3677173986@googlegroups.com> |
| In reply to | #44585 |
Sorry about the spacing I didn't realise that tabbing would post it. Its untested, but would this be the general gist of translation I wanted to ask ? NN
[toc] | [prev] | [next] | [standalone]
| From | november.nihal@gmail.com |
|---|---|
| Date | 2016-01-05 08:18 -0800 |
| Message-ID | <ce3a2341-2b6f-4c96-be67-87d1763bec50@googlegroups.com> |
| In reply to | #44586 |
On Tuesday, 5 January 2016 16:07:15 UTC, novembe...@gmail.com wrote: > Sorry about the spacing I didn't realise that tabbing would post it. > Its untested, but would this be the general gist of translation I wanted to ask ? > > NN Re-posting : : update-links3 begin @ dup if abort then 2dup = until ; : update-links2 ['] update-links3 catch if drop nip else 2drop r> @ swap ! exit then ; : update-links1 begin dup @ dup while r@ update-links2 repeat ; : update-links ( super link -- ) r> update-links1 r> drop 2drop ;
[toc] | [prev] | [next] | [standalone]
Page 1 of 5 [1] 2 3 4 5 Next page →
Back to top | Article view | comp.lang.forth
csiph-web