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


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

BEGIN with multiple AGAINs?

Started byDavid J <skamolex@gmail.com>
First post2014-05-21 13:44 -0700
Last post2014-06-28 14:00 -0700
Articles 8 on this page of 88 — 20 participants

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


Contents

  BEGIN with multiple AGAINs? David J <skamolex@gmail.com> - 2014-05-21 13:44 -0700
    Re: BEGIN with multiple AGAINs? rickman <gnuarm@gmail.com> - 2014-05-21 17:11 -0400
    Re: BEGIN with multiple AGAINs? mhx@iae.nl - 2014-05-21 14:31 -0700
      Re: BEGIN with multiple AGAINs? mhx@iae.nl - 2014-05-21 15:07 -0700
    Re: BEGIN with multiple AGAINs? David J <skamolex@gmail.com> - 2014-05-21 14:51 -0700
    Re: BEGIN with multiple AGAINs? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-05-21 21:59 +0000
    Re: BEGIN with multiple AGAINs? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2014-05-22 00:09 +0100
    Re: BEGIN with multiple AGAINs? David J <skamolex@gmail.com> - 2014-05-21 22:31 -0700
      Re: BEGIN with multiple AGAINs? rickman <gnuarm@gmail.com> - 2014-05-22 01:58 -0400
        Re: BEGIN with multiple AGAINs? David J <skamolex@gmail.com> - 2014-05-22 08:02 -0700
          Re: BEGIN with multiple AGAINs? rickman <gnuarm@gmail.com> - 2014-05-22 11:31 -0400
            Re: BEGIN with multiple AGAINs? David J <skamolex@gmail.com> - 2014-05-22 11:03 -0700
              Re: BEGIN with multiple AGAINs? forthisit@gmail.com - 2014-05-22 11:13 -0700
                Re: BEGIN with multiple AGAINs? forthisit@gmail.com - 2014-05-22 11:15 -0700
          Re: BEGIN with multiple AGAINs? forthisit@gmail.com - 2014-05-22 08:57 -0700
    Re: BEGIN with multiple AGAINs? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-05-22 13:47 +0000
    Re: BEGIN with multiple AGAINs? David J <skamolex@gmail.com> - 2014-05-22 11:27 -0700
      Re: BEGIN with multiple AGAINs? David J <skamolex@gmail.com> - 2014-05-22 11:38 -0700
      Re: BEGIN with multiple AGAINs? rickman <gnuarm@gmail.com> - 2014-05-22 14:47 -0400
        Re: BEGIN with multiple AGAINs? David J <skamolex@gmail.com> - 2014-05-22 12:22 -0700
    Re: BEGIN with multiple AGAINs? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-05-23 02:44 -0500
      Re: BEGIN with multiple AGAINs? David J <skamolex@gmail.com> - 2014-05-23 02:06 -0700
        Re: BEGIN with multiple AGAINs? rickman <gnuarm@gmail.com> - 2014-05-23 05:47 -0400
      Re: BEGIN with multiple AGAINs? "Elizabeth D. Rather" <erather@forth.com> - 2014-05-24 13:04 -1000
        Re: BEGIN with multiple AGAINs? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-05-25 15:06 -0500
          Re: BEGIN with multiple AGAINs? "Elizabeth D. Rather" <erather@forth.com> - 2014-05-25 16:37 -1000
            Re: BEGIN with multiple AGAINs? rickman <gnuarm@gmail.com> - 2014-05-25 23:56 -0400
            Re: BEGIN with multiple AGAINs? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-05-26 04:02 -0500
              Re: BEGIN with multiple AGAINs? "Elizabeth D. Rather" <erather@forth.com> - 2014-05-26 07:44 -1000
    Re: BEGIN with multiple AGAINs? "Clyde W. Phillips Jr." <cwpjr02@gmail.com> - 2014-05-23 12:39 -0700
    Re: BEGIN with multiple AGAINs? "Clyde W. Phillips Jr." <cwpjr02@gmail.com> - 2014-05-23 16:49 -0700
      Re: BEGIN with multiple AGAINs? Coos Haak <chforth@hccnet.nl> - 2014-05-24 02:00 +0200
    Re: BEGIN with multiple AGAINs? "Clyde W. Phillips Jr." <cwpjr02@gmail.com> - 2014-05-23 17:00 -0700
    Re: BEGIN with multiple AGAINs? "Clyde W. Phillips Jr." <cwpjr02@gmail.com> - 2014-05-23 21:29 -0700
      Re: BEGIN with multiple AGAINs? David J <skamolex@gmail.com> - 2014-05-24 08:10 -0700
        Re: BEGIN with multiple AGAINs? "Clyde W. Phillips Jr." <cwpjr02@gmail.com> - 2014-05-24 13:55 -0700
          Re: BEGIN with multiple AGAINs? rickman <gnuarm@gmail.com> - 2014-05-24 18:41 -0400
    Re: BEGIN with multiple AGAINs? Bee <forth@calcentral.com> - 2014-05-24 17:09 -0700
      Re: BEGIN with multiple AGAINs? "Clyde W. Phillips Jr." <cwpjr02@gmail.com> - 2014-05-24 18:05 -0700
        Re: BEGIN with multiple AGAINs? "Clyde W. Phillips Jr." <cwpjr02@gmail.com> - 2014-05-24 18:09 -0700
          Re: BEGIN with multiple AGAINs? ForthFreak <forthfreak@gmail.com> - 2014-05-25 02:03 -0700
            Re: BEGIN with multiple AGAINs? rickman <gnuarm@gmail.com> - 2014-05-25 05:18 -0400
              Re: BEGIN with multiple AGAINs? ForthFreak <forthfreak@gmail.com> - 2014-05-25 03:01 -0700
                Re: BEGIN with multiple AGAINs? David J <skamolex@gmail.com> - 2014-05-25 14:10 -0700
                  Re: BEGIN with multiple AGAINs? "Clyde W. Phillips Jr." <cwpjr02@gmail.com> - 2014-05-25 15:19 -0700
    Re: BEGIN with multiple AGAINs? Bee <forth@calcentral.com> - 2014-05-25 10:13 -0700
      Re: BEGIN with multiple AGAINs? David J <skamolex@gmail.com> - 2014-05-25 15:22 -0700
        Re: BEGIN with multiple AGAINs? BruceMcF <agila61@netscape.net> - 2014-06-12 13:11 -0700
          Re: BEGIN with multiple AGAINs? David J <skamolex@gmail.com> - 2014-06-12 19:06 -0700
    Re: BEGIN with multiple AGAINs? BruceMcF <agila61@netscape.net> - 2014-06-12 12:36 -0700
      Re: BEGIN with multiple AGAINs? BruceMcF <agila61@netscape.net> - 2014-06-12 19:50 -0700
        Re: BEGIN with multiple AGAINs? rickman <gnuarm@gmail.com> - 2014-06-13 01:02 -0400
          Re: BEGIN with multiple AGAINs? "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-13 04:16 -0400
            Re: BEGIN with multiple AGAINs? rickman <gnuarm@gmail.com> - 2014-06-13 05:22 -0400
              Re: BEGIN with multiple AGAINs? "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-14 00:33 -0400
                Re: BEGIN with multiple AGAINs? rickman <gnuarm@gmail.com> - 2014-06-14 01:15 -0400
                Re: BEGIN with multiple AGAINs? bruce.mcfarling@gmail.com - 2014-06-13 23:45 -0700
                  Re: BEGIN with multiple AGAINs? bruce.mcfarling@gmail.com - 2014-06-14 00:00 -0700
            Re: BEGIN with multiple AGAINs? rickman <gnuarm@gmail.com> - 2014-06-13 05:26 -0400
              Re: BEGIN with multiple AGAINs? "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-14 00:32 -0400
            Re: BEGIN with multiple AGAINs? "Alex McDonald" <blog@rivadpm.com> - 2014-06-13 12:27 +0100
              Re: BEGIN with multiple AGAINs? "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-14 00:35 -0400
                Re: BEGIN with multiple AGAINs? rickman <gnuarm@gmail.com> - 2014-06-14 01:22 -0400
                  Re: BEGIN with multiple AGAINs? "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-15 08:23 -0400
                    Re: BEGIN with multiple AGAINs? BruceMcF <agila61@netscape.net> - 2014-06-15 11:57 -0700
                    Re: BEGIN with multiple AGAINs? "Elizabeth D. Rather" <erather@forth.com> - 2014-06-15 09:13 -1000
                Re: BEGIN with multiple AGAINs? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-06-14 04:32 -0500
                  Re: BEGIN with multiple AGAINs? "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-15 08:23 -0400
                    Re: BEGIN with multiple AGAINs? "Alex McDonald" <blog@rivadpm.com> - 2014-06-15 19:20 +0100
                Re: BEGIN with multiple AGAINs? "Alex McDonald" <blog@rivadpm.com> - 2014-06-14 23:19 +0100
                  Re: BEGIN with multiple AGAINs? "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-15 08:36 -0400
                    Re: BEGIN with multiple AGAINs? "Alex McDonald" <blog@rivadpm.com> - 2014-06-15 19:18 +0100
                      Re: BEGIN with multiple AGAINs? "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-26 18:34 -0400
                        Re: BEGIN with multiple AGAINs? bruce.mcfarling@gmail.com - 2014-06-26 16:04 -0700
                    Re: BEGIN with multiple AGAINs? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-06-15 19:27 +0000
                Re: BEGIN with multiple AGAINs? Mark Wills <markwills1970@gmail.com> - 2014-06-16 01:45 -0700
            Re: BEGIN with multiple AGAINs? BruceMcF <agila61@netscape.net> - 2014-06-13 09:14 -0700
              Re: BEGIN with multiple AGAINs? november.nihal@gmail.com - 2014-06-13 09:44 -0700
              Re: BEGIN with multiple AGAINs? "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-14 00:32 -0400
                Re: BEGIN with multiple AGAINs? bruce.mcfarling@gmail.com - 2014-06-13 23:25 -0700
          Re: BEGIN with multiple AGAINs? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-06-13 03:13 -0500
          Re: BEGIN with multiple AGAINs? BruceMcF <agila61@netscape.net> - 2014-06-13 08:38 -0700
            Re: BEGIN with multiple AGAINs? rickman <gnuarm@gmail.com> - 2014-06-13 13:29 -0400
              Re: BEGIN with multiple AGAINs? BruceMcF <agila61@netscape.net> - 2014-06-13 11:49 -0700
                Re: BEGIN with multiple AGAINs? "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-14 00:41 -0400
                  Re: BEGIN with multiple AGAINs? Elizabeth D Rather <erather@forth.com> - 2014-06-13 19:08 -1000
        Re: BEGIN with multiple AGAINs? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2014-06-13 21:27 +0100
    Re: BEGIN with multiple AGAINs? BruceMcF <agila61@netscape.net> - 2014-06-28 14:00 -0700

Page 5 of 5 — ← Prev page 1 2 3 4 [5]


#31475

FromAndrew Haley <andrew29@littlepinkcloud.invalid>
Date2014-06-13 03:13 -0500
Message-ID<U6SdnYnh6LwLLwfOnZ2dnUVZ_oidnZ2d@supernews.com>
In reply to#31471
rickman <gnuarm@gmail.com> wrote:
> 
> I don't feel like digging into the standard at the moment.  Is the XT 
> guaranteed to be one cell in all machines or is this an environmental 
> dependency?

You lazy so-and-so!  :-)

It's one cell.

Andrew.

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


#31487

FromBruceMcF <agila61@netscape.net>
Date2014-06-13 08:38 -0700
Message-ID<77b5b9fe-e607-458d-ae0c-b1d305dfba8d@googlegroups.com>
In reply to#31471
On Friday, June 13, 2014 1:02:40 AM UTC-4, rickman wrote:
> : run-list ( a -- ) \ address of a structure with an op-sequence 
>      BEGIN DUP @ EXECUTE WHILE CELL+ AGAIN DROP ;
 
> : run-machine ( a -- ) \ address of a structure with an op-sequence
>      >R BEGIN 
>         R@ run-list
>      AGAIN ;

Yes, the factoring is better ... if there's a cell-count on hand, it'd make sense to use it:

: run-list ( a -- ) \ address of a structure with an op-sequence
   BEGIN cell-count EXECUTE 0= UNTIL ;

... but if not, WHILE does allow tackling just the top of stack, though WHILE leaves (CT: dest -- orig dest) while compiling, so needs REPEAT (effectively AGAIN THEN) rather than AGAIN:

: run-list ( a -- ) \ address of a structure with an op-sequence
   BEGIN DUP @ EXECUTE WHILE CELL+ REPEAT ;

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


#31493

Fromrickman <gnuarm@gmail.com>
Date2014-06-13 13:29 -0400
Message-ID<lnfce3$6ov$1@dont-email.me>
In reply to#31487
On 6/13/2014 11:38 AM, BruceMcF wrote:
> On Friday, June 13, 2014 1:02:40 AM UTC-4, rickman wrote:
>> : run-list ( a -- ) \ address of a structure with an op-sequence
>>       BEGIN DUP @ EXECUTE WHILE CELL+ AGAIN DROP ;
>
>> : run-machine ( a -- ) \ address of a structure with an op-sequence
>>       >R BEGIN
>>          R@ run-list
>>       AGAIN ;
>
> Yes, the factoring is better ... if there's a cell-count on hand, it'd make sense to use it:
>
> : run-list ( a -- ) \ address of a structure with an op-sequence
>     BEGIN cell-count EXECUTE 0= UNTIL ;
>
> ... but if not, WHILE does allow tackling just the top of stack, though WHILE leaves (CT: dest -- orig dest) while compiling, so needs REPEAT (effectively AGAIN THEN) rather than AGAIN:
>
> : run-list ( a -- ) \ address of a structure with an op-sequence
>     BEGIN DUP @ EXECUTE WHILE CELL+ REPEAT ;

Yes, of course.  Don't you still need the DROP to remove the address 
from the data stack?

-- 

Rick

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


#31497

FromBruceMcF <agila61@netscape.net>
Date2014-06-13 11:49 -0700
Message-ID<265750de-b6df-4653-b8e9-adabb463c84c@googlegroups.com>
In reply to#31493
On Friday, June 13, 2014 1:29:51 PM UTC-4, rickman wrote:
> Yes, of course.  Don't you still need the DROP to remove the address  
> from the data stack?

Yes ...

: run-list ( a -- ) \ address of a structure with an op-sequence
   BEGIN cell-count EXECUTE 0= UNTIL DROP ;

: run-list ( a -- ) \ address of a structure with an op-sequence
   BEGIN DUP @ EXECUTE WHILE CELL+ REPEAT DROP ;

... I've got that muddled with an original with the stack picture was:
   ( a1 -- a2 )

... so if you wanted you could:
   R@ SWAP - cell/

... to find out how far you walked the list until terminating.

\  NB. that's cell/ from toolkit. Compact form:
      : cell/ ( u1 -- u2 ) 1 cells / ;

Verbose portable library form:

      1 CELLS CONSTANT /cell
      /cell 1 = [IF]
         : cell/ ; \ u1 -- u2
      [ELSE] /cell 2 = [IF]
            : cell/ 2/ ;
         [ELSE] /cell 4 = [IF]
               : cell/ 2/ 2/ ;
            [ELSE] : cell/ /cell / ;
            [THEN]
         [THEN]
      [THEN]

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


#31512

From"Rod Pemberton" <dont_use_email@xnothavet.cqm>
Date2014-06-14 00:41 -0400
Message-ID<op.xhfgmxhq6zenlw@localhost>
In reply to#31497
On Fri, 13 Jun 2014 14:49:57 -0400, BruceMcF <agila61@netscape.net> wrote:
> On Friday, June 13, 2014 1:29:51 PM UTC-4, rickman wrote:

>> Yes, of course.  Don't you still need the DROP to remove the address
>> from the data stack?
>
> Yes ...
>

And, yet, you guys don't see stuff like this, missing DROPs DUPs, by you,
me, numerous etc people here, over and over again across the years, to be
indicative of Forth being error prone? ... (rhetorical, IMO)


RP

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


#31515

FromElizabeth D Rather <erather@forth.com>
Date2014-06-13 19:08 -1000
Message-ID<nNGdnUdaRvwhRQbOnZ2dnUVZ_sCdnZ2d@supernews.com>
In reply to#31512
On 6/13/2014 6:41 PM, Rod Pemberton wrote:
> On Fri, 13 Jun 2014 14:49:57 -0400, BruceMcF <agila61@netscape.net> wrote:
>> On Friday, June 13, 2014 1:29:51 PM UTC-4, rickman wrote:
>
>>> Yes, of course.  Don't you still need the DROP to remove the address
>>> from the data stack?
>>
>> Yes ...
>>
>
> And, yet, you guys don't see stuff like this, missing DROPs DUPs, by you,
> me, numerous etc people here, over and over again across the years, to be
> indicative of Forth being error prone? ... (rhetorical, IMO)

The problem is people type stuff in messages that they haven't tested. 
We get to enjoy the exercise of finding each others' bugs. This stuff 
pops right out when you actually try it!

Cheers,
Elizabeth

-- 
==================================================
Elizabeth D. Rather   (US & Canada)   800-55-FORTH
FORTH Inc.                         +1 310.999.6784
5959 West Century Blvd. Suite 700
Los Angeles, CA 90045
http://www.forth.com

"Forth-based products and Services for real-time
applications since 1973."
==================================================

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


#31498

FromGerry Jackson <gerry@jackson9000.fsnet.co.uk>
Date2014-06-13 21:27 +0100
Message-ID<lnfmr0$lk6$1@dont-email.me>
In reply to#31468
On 13/06/2014 03:50, BruceMcF wrote:
> On Thursday, June 12, 2014 3:36:06 PM UTC-4, BruceMcF wrote:
>> CREATE op-sequence ' op-a , ' op-b , ' op-c , ' op-d , ' FALSE ,
>
>> : run-machine ( a -- ) \ address of a structure with an op-sequence
>>     >R BEGIN
>>        R@ REPEAT DUP CELL+ SWAP @ EXECUTE 0= UNTIL DROP
>>     AGAIN ;
>
> Sadly I wasn't drinking when I wrote that ... that is, of course:
>
> : run-machine ( a -- ) \ address of a structure with an op-sequence
>     >R BEGIN
>        R@ BEGIN DUP CELL+ SWAP @ EXECUTE 0= UNTIL DROP
>     AGAIN ;
>

This reminded me that a state machine can be implemented using CREATE 
... DOES> e.g.

defer init
: ?key ( x ch -- f )    \ Test purposes only
    nip key dup [char] q = abort" Aborted"
    dup emit =
;

\ all op's are ( ad -- )
: op-d ." op-d " [char] d ?key drop init ;
: op-c ." op-c " [char] c ?key if init exit then does> op-d ;
: op-b ." op-b " [char] b ?key if init exit then does> op-c ;
: op-a ." op-a " [char] a ?key if init exit then does> op-b ;

:noname does> op-a ; is init

create run init
cr run 0 >in !       \ loop until 'q' is pressed

Not very practical as no definitions can be made after RUN before running it

-- 
Gerry

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


#32023

FromBruceMcF <agila61@netscape.net>
Date2014-06-28 14:00 -0700
Message-ID<4c1555b0-c724-4779-b6b9-b30428d9802a@googlegroups.com>
In reply to#30533
On Wednesday, May 21, 2014 4:44:45 PM UTC-4, David J wrote:
> Trying to think through Forth flow.  I have a situation where I need to call a succession of words, endlessly.  Each word returns a status (on the stack, of course).  This status is evaluated and either the next word in the list is called or else execution goes back to the BEGINning of the list.

> So, can an AGAIN be used in each IF ELSE test? Or a REPEAT?  Or is there a better way to handle this in Forth?

On the original question, I was reminded in going through an old project of multiple WHILEs. Multiple WHILEs with different code executing for the different exit cases also drove me crazy to untangle, but if the stack is balanced the same at each WHILE then its just adding an extra THEN for each extra WHILE

Say there is task1-task4, with each ( -- ior ) where an ior=0 is success and then the next task in turn should be executed. I presume there is a watchdog process that is sampling a variable "status"

   BEGIN
      BEGIN
         task1 ?DUP 0= WHILE
            task2 ?DUP 0= WHILE
               task3 ?DUP 0= WHILE
                  task4 ?DUP 0= WHILE
                     0 status !
      REPEAT THEN THEN THEN
      status !
   AGAIN

[toc] | [prev] | [standalone]


Page 5 of 5 — ← Prev page 1 2 3 4 [5]

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


csiph-web