Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #11405 > unrolled thread

Another question re LEAVE

Started byMark Wills <markrobertwills@yahoo.co.uk>
First post2012-04-19 06:44 -0700
Last post2012-04-20 04:42 -0700
Articles 10 — 5 participants

Back to article view | Back to comp.lang.forth


Contents

  Another question re LEAVE Mark Wills <markrobertwills@yahoo.co.uk> - 2012-04-19 06:44 -0700
    Re: Another question re LEAVE Bernd Paysan <bernd.paysan@gmx.de> - 2012-04-19 18:15 +0200
      Re: Another question re LEAVE Mark Wills <markrobertwills@yahoo.co.uk> - 2012-04-19 10:14 -0700
      Re: Another question re LEAVE George Hubert <georgeahubert@yahoo.co.uk> - 2012-04-19 11:24 -0700
        Re: Another question re LEAVE Mark Wills <markrobertwills@yahoo.co.uk> - 2012-04-19 12:34 -0700
    Re: Another question re LEAVE BruceMcF <agila61@netscape.net> - 2012-04-19 10:15 -0700
    Re: Another question re LEAVE mhx@iae.nl (Marcel Hendrix) - 2012-04-19 20:14 +0200
      Re: Another question re LEAVE Mark Wills <markrobertwills@yahoo.co.uk> - 2012-04-19 12:31 -0700
    Re: Another question re LEAVE BruceMcF <agila61@netscape.net> - 2012-04-19 16:59 -0700
      Re: Another question re LEAVE Mark Wills <markrobertwills@yahoo.co.uk> - 2012-04-20 04:42 -0700

#11405 — Another question re LEAVE

FromMark Wills <markrobertwills@yahoo.co.uk>
Date2012-04-19 06:44 -0700
SubjectAnother question re LEAVE
Message-ID<c7b128cb-0606-4c35-aeb3-b76678fa4a33@21g2000vbh.googlegroups.com>
See original topic here:

http://groups.google.com/group/comp.lang.forth/browse_thread/thread/34f5f0a8a70dc66b?tvc=2

I'm starting a new thread because google groups won't let me reply to
the thread - on the author. No idea why.

Is LEAVE *ever* going to be used *outside* of an IF...ENDIF block? I
think no. To illustrate, the following simply doesn't make sense:

12345 0 DO <some stuff> LEAVE LOOP

That makes no sense at all; you just wouldn't use a loop at all, would
you?

My current solution relies on LEAVE being inside an IF THEN block (my
LEAVE code looks like this):

data docol
data compile,droplf \ drop loop frame from return stack
data over
data ghere,sub,sub2,sub2  \ HERE - 2- 2-
data compile,branch,comma
data exit

See that OVER? That's required because data laid down by IF is above
the data I need on the stack. As long as LEAVE occurs in an IF, it's
fine.

My solution is kind of clunky, but does work, and will nest correctly.
The following program:

: TEST
    1000 0 DO
      CR ." hello " I 2 = IF LEAVE THEN
      5000 0 DO
        ." fred " I 4 = IF LEAVE THEN
      LOOP
    LOOP
;

Produces the following output:

hello fred fred fred fred fred
hello fred fred fred fred fred
hello

Which agrees with GForth.

I could show you how it works, but you'd all just berate me! Anyway,
it's all for naught if it turns out there is some scenario where LEAVE
could appear outside of an IF...THEN block.

Mark

[toc] | [next] | [standalone]


#11409

FromBernd Paysan <bernd.paysan@gmx.de>
Date2012-04-19 18:15 +0200
Message-ID<jmpdnv$f83$1@online.de>
In reply to#11405
Mark Wills wrote:

> See original topic here:
> 
> 
http://groups.google.com/group/comp.lang.forth/browse_thread/thread/34f5f0a8a70dc66b?tvc=2
> 
> I'm starting a new thread because google groups won't let me reply to
> the thread - on the author. No idea why.
> 
> Is LEAVE *ever* going to be used *outside* of an IF...ENDIF block?

No, of course not.  But it can be inside a nested IF THEN block.

I've an ?LEAVE, which is equivalent to IF LEAVE THEN, but takes only one 
branch.  That one does occur within the DO LOOP itself.

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://bernd-paysan.de/

[toc] | [prev] | [next] | [standalone]


#11411

FromMark Wills <markrobertwills@yahoo.co.uk>
Date2012-04-19 10:14 -0700
Message-ID<8d4b9ed7-6c1c-4f1c-9ee1-1b6d09aea45b@d20g2000vbh.googlegroups.com>
In reply to#11409
On Apr 19, 5:15 pm, Bernd Paysan <bernd.pay...@gmx.de> wrote:
> Mark Wills wrote:
> > See original topic here:
>
> http://groups.google.com/group/comp.lang.forth/browse_thread/thread/3...
>
>
>
> > I'm starting a new thread because google groups won't let me reply to
> > the thread - on the author. No idea why.
>
> > Is LEAVE *ever* going to be used *outside* of an IF...ENDIF block?
>
> No, of course not.  But it can be inside a nested IF THEN block.
>
> I've an ?LEAVE, which is equivalent to IF LEAVE THEN, but takes only one
> branch.  That one does occur within the DO LOOP itself.
>
> --
> Bernd Paysan
> "If you want it done right, you have to do it yourself"http://bernd-paysan.de/

Thanks, I thought so - just wanted to make sure.

[toc] | [prev] | [next] | [standalone]


#11420

FromGeorge Hubert <georgeahubert@yahoo.co.uk>
Date2012-04-19 11:24 -0700
Message-ID<0d736c82-5c1e-48d3-b43c-26959902de41@i2g2000vbd.googlegroups.com>
In reply to#11409
On Apr 19, 5:15 pm, Bernd Paysan <bernd.pay...@gmx.de> wrote:
> Mark Wills wrote:
> > See original topic here:
>
> http://groups.google.com/group/comp.lang.forth/browse_thread/thread/3...
>
>
>
> > I'm starting a new thread because google groups won't let me reply to
> > the thread - on the author. No idea why.
>
> > Is LEAVE *ever* going to be used *outside* of an IF...ENDIF block?
>
> No, of course not.  But it can be inside a nested IF THEN block.
>
> I've an ?LEAVE, which is equivalent to IF LEAVE THEN, but takes only one
> branch.  That one does occur within the DO LOOP itself.
>

Win32forth has ?LEAVE as well, for the same reason.

George Hubert

> --
> Bernd Paysan
> "If you want it done right, you have to do it yourself"http://bernd-paysan.de/

[toc] | [prev] | [next] | [standalone]


#11427

FromMark Wills <markrobertwills@yahoo.co.uk>
Date2012-04-19 12:34 -0700
Message-ID<10471b8e-9fb8-404e-97ba-d62c209c692e@d4g2000vbn.googlegroups.com>
In reply to#11420
On Apr 19, 7:24 pm, George Hubert <georgeahub...@yahoo.co.uk> wrote:
> On Apr 19, 5:15 pm, Bernd Paysan <bernd.pay...@gmx.de> wrote:
>
>
>
>
>
> > Mark Wills wrote:
> > > See original topic here:
>
> >http://groups.google.com/group/comp.lang.forth/browse_thread/thread/3...
>
> > > I'm starting a new thread because google groups won't let me reply to
> > > the thread - on the author. No idea why.
>
> > > Is LEAVE *ever* going to be used *outside* of an IF...ENDIF block?
>
> > No, of course not.  But it can be inside a nested IF THEN block.
>
> > I've an ?LEAVE, which is equivalent to IF LEAVE THEN, but takes only one
> > branch.  That one does occur within the DO LOOP itself.
>
> Win32forth has ?LEAVE as well, for the same reason.
>
> George Hubert
>
>
>
> > --
> > Bernd Paysan
> > "If you want it done right, you have to do it yourself"http://bernd-paysan.de/

I thought of ?leave also.

: foo 100 0 do bigError? ?leave bar loop ;

I would suggest that it is a good candidate for standardization. It is
not trivial to implement LEAVE IMHO.

Mark

[toc] | [prev] | [next] | [standalone]


#11413

FromBruceMcF <agila61@netscape.net>
Date2012-04-19 10:15 -0700
Message-ID<6ab47dfd-764e-4070-aec7-19bbfc2af35c@m13g2000yqc.googlegroups.com>
In reply to#11405
On Apr 19, 9:44 am, Mark Wills <markrobertwi...@yahoo.co.uk> wrote:
> Is LEAVE *ever* going to be used *outside* of an IF...ENDIF block? I
> think no. To illustrate, the following simply doesn't make sense:

It'd be in a conditional block of some kind ~ it could be a CASE
statement, but that's an elaborated IF-THEN structure.

[toc] | [prev] | [next] | [standalone]


#11419

Frommhx@iae.nl (Marcel Hendrix)
Date2012-04-19 20:14 +0200
Message-ID<71891516998435@frunobulax.edu>
In reply to#11405
Mark Wills <markrobertwills@yahoo.co.uk> writes Re: Another question re LEAVE
[..]
> Is LEAVE *ever* going to be used *outside* of an IF...ENDIF block? I
> think no. To illustrate, the following simply doesn't make sense:
[..]

It perfectly makes sense.

: WAIT<NAK> ( -- <true if error> )
	crc TRUE  
	#Retries
	    0 DO PURGE.RCVR 1 ?CHAR
		 CASE
		  <Nak> OF FALSE TO crc 0= LEAVE ENDOF
		   'C'  OF  TRUE TO crc 0= LEAVE ENDOF
		   	    DUP ." {" B. ." }"
		 ENDCASE
	    LOOP
	autodetect IF  NIP  ELSE  SWAP TO crc  ENDIF
	DUP IF	CR ^G EMIT  ." Receiver does not respond." CR ENDIF ; 

-marcel

[toc] | [prev] | [next] | [standalone]


#11426

FromMark Wills <markrobertwills@yahoo.co.uk>
Date2012-04-19 12:31 -0700
Message-ID<f56b5789-dc51-4c4d-a6bd-bece7c5365e9@d4g2000vbn.googlegroups.com>
In reply to#11419
On Apr 19, 7:14 pm, m...@iae.nl (Marcel Hendrix) wrote:
> Mark Wills <markrobertwi...@yahoo.co.uk> writes Re: Another question re LEAVE
> [..]> Is LEAVE *ever* going to be used *outside* of an IF...ENDIF block? I
> > think no. To illustrate, the following simply doesn't make sense:
>
> [..]
>
> It perfectly makes sense.
>
> : WAIT<NAK> ( -- <true if error> )
>         crc TRUE
>         #Retries
>             0 DO PURGE.RCVR 1 ?CHAR
>                  CASE
>                   <Nak> OF FALSE TO crc 0= LEAVE ENDOF
>                    'C'  OF  TRUE TO crc 0= LEAVE ENDOF
>                             DUP ." {" B. ." }"
>                  ENDCASE
>             LOOP
>         autodetect IF  NIP  ELSE  SWAP TO crc  ENDIF
>         DUP IF  CR ^G EMIT  ." Receiver does not respond." CR ENDIF ;
>
> -marcel

I suspect that the way I have written LEAVE and the way CASE is
implemented means your example will work.
I'll give it a try. Thanks.

[toc] | [prev] | [next] | [standalone]


#11451

FromBruceMcF <agila61@netscape.net>
Date2012-04-19 16:59 -0700
Message-ID<c7541214-45f0-4e84-8ade-b7f205937f68@12g2000vba.googlegroups.com>
In reply to#11405
On Apr 19, 9:44 am, Mark Wills <markrobertwi...@yahoo.co.uk> wrote:
> : TEST
>     1000 0 DO
>       CR ." hello " I 2 = IF LEAVE THEN
>       5000 0 DO
>         ." fred " I 4 = IF LEAVE THEN
>       LOOP
>     LOOP
> ;

But does the following work:

: TEST
    1000 0 DO
      CR ." Hello " I 2 = IF LEAVE THEN
      5000 0 DO
         ." Mr. " I 1 AND IF
            ." Odd .. "
         ELSE ." Even .. " I 4 = IF LEAVE THEN
         THEN
      LOOP
    LOOP
;

In Gforth, I get:
test
Hello Mr. Even .. Mr. Odd .. Mr. Even .. Mr. Odd .. Mr. Even
Hello Mr. Even .. Mr. Odd .. Mr. Even .. Mr. Odd .. Mr. Even
Hello

[toc] | [prev] | [next] | [standalone]


#11470

FromMark Wills <markrobertwills@yahoo.co.uk>
Date2012-04-20 04:42 -0700
Message-ID<6ef8cc4d-452c-43c7-ac69-5637afc60689@h9g2000yqe.googlegroups.com>
In reply to#11451
On Apr 20, 12:59 am, BruceMcF <agil...@netscape.net> wrote:
> On Apr 19, 9:44 am, Mark Wills <markrobertwi...@yahoo.co.uk> wrote:
>
> > : TEST
> >     1000 0 DO
> >       CR ." hello " I 2 = IF LEAVE THEN
> >       5000 0 DO
> >         ." fred " I 4 = IF LEAVE THEN
> >       LOOP
> >     LOOP
> > ;
>
> But does the following work:
>
> : TEST
>     1000 0 DO
>       CR ." Hello " I 2 = IF LEAVE THEN
>       5000 0 DO
>          ." Mr. " I 1 AND IF
>             ." Odd .. "
>          ELSE ." Even .. " I 4 = IF LEAVE THEN
>          THEN
>       LOOP
>     LOOP
> ;
>
> In Gforth, I get:
> test
> Hello Mr. Even .. Mr. Odd .. Mr. Even .. Mr. Odd .. Mr. Even
> Hello Mr. Even .. Mr. Odd .. Mr. Even .. Mr. Odd .. Mr. Even
> Hello

Bruce,

I get exactly the same output.

Thanks

Mark

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.forth


csiph-web