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


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

continue equivalent in Forth?

Started byprogrammingkidx@gmail.com
First post2012-08-18 19:28 -0700
Last post2012-08-19 14:43 -0700
Articles 20 on this page of 83 — 16 participants

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


Contents

  continue equivalent in Forth? programmingkidx@gmail.com - 2012-08-18 19:28 -0700
    Re: continue equivalent in Forth? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-08-19 01:43 -0500
    Re: continue equivalent in Forth? mhx@iae.nl - 2012-08-19 03:40 -0700
    Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-19 21:07 +1000
      Re: continue equivalent in Forth? Coos Haak <chforth@hccnet.nl> - 2012-08-19 13:55 +0200
        Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-20 22:13 +1000
      Re: continue equivalent in Forth? Coos Haak <chforth@hccnet.nl> - 2012-08-19 14:18 +0200
        Re: continue equivalent in Forth? mhx@iae.nl (Marcel Hendrix) - 2012-08-19 14:57 +0200
          Re: continue equivalent in Forth? Coos Haak <chforth@hccnet.nl> - 2012-08-19 16:39 +0200
        Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-20 22:18 +1000
        Re: continue equivalent in Forth? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-21 00:05 -0400
          Re: continue equivalent in Forth? hughaguilar96@yahoo.com - 2012-08-20 21:17 -0700
            Re: continue equivalent in Forth? Alex McDonald <blog@rivadpm.com> - 2012-08-21 02:40 -0700
            Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-22 15:33 +1000
          Re: continue equivalent in Forth? Alex McDonald <blog@rivadpm.com> - 2012-08-21 02:37 -0700
            Re: continue equivalent in Forth? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-22 00:53 -0400
              Re: continue equivalent in Forth? Alex McDonald <blog@rivadpm.com> - 2012-08-22 04:10 -0700
          Re: continue equivalent in Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-21 11:40 +0000
            Re: continue equivalent in Forth? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-22 00:53 -0400
              Re: continue equivalent in Forth? "Elizabeth D. Rather" <erather@forth.com> - 2012-08-21 21:18 -1000
                Re: continue equivalent in Forth? hughaguilar96@yahoo.com - 2012-08-22 00:52 -0700
                  Re: continue equivalent in Forth? Alex McDonald <blog@rivadpm.com> - 2012-08-22 04:12 -0700
                  Re: continue equivalent in Forth? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-22 07:43 -0400
                    Re: continue equivalent in Forth? hughaguilar96@yahoo.com - 2012-08-22 20:04 -0700
                      Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-25 15:50 +1000
                        Re: continue equivalent in Forth? "Elizabeth D. Rather" <erather@forth.com> - 2012-08-24 21:03 -1000
                          Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-26 22:13 +1000
                        Re: continue equivalent in Forth? Coos Haak <chforth@hccnet.nl> - 2012-08-25 10:40 +0200
                          Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-29 18:29 +1000
                            Re: continue equivalent in Forth? Coos Haak <chforth@hccnet.nl> - 2012-08-29 21:26 +0200
                  Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-26 22:33 +1000
                Re: continue equivalent in Forth? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-22 07:46 -0400
                  Re: continue equivalent in Forth? "Elizabeth D. Rather" <erather@forth.com> - 2012-08-22 07:20 -1000
              Re: continue equivalent in Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-22 09:37 +0000
                Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-22 20:46 +1000
                Re: continue equivalent in Forth? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-22 07:44 -0400
                  Re: continue equivalent in Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-22 14:26 +0000
                    Re: continue equivalent in Forth? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2012-08-24 17:34 +0100
                      Re: continue equivalent in Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-24 16:50 +0000
                        Re: continue equivalent in Forth? Mark Wills <markrobertwills@yahoo.co.uk> - 2012-08-24 13:47 -0700
                          Re: continue equivalent in Forth? mhx@iae.nl - 2012-08-24 22:51 -0700
                          Re: continue equivalent in Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-25 08:55 +0000
                          Re: continue equivalent in Forth? hughaguilar96@yahoo.com - 2012-08-25 20:47 -0700
                            Re: continue equivalent in Forth? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-26 06:20 -0400
                              Re: continue equivalent in Forth? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-08-26 11:04 -0500
                                Re: continue equivalent in Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-26 16:06 +0000
                                  Re: continue equivalent in Forth? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-08-26 15:32 -0500
                                    Re: continue equivalent in Forth? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-08-27 22:58 -0700
                        Re: continue equivalent in Forth? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2012-08-26 22:07 +0100
                          Re: continue equivalent in Forth? mhx@iae.nl (Marcel Hendrix) - 2012-08-27 18:14 +0200
                            Re: continue equivalent in Forth? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2012-08-27 18:22 +0100
                              Re: continue equivalent in Forth? mhx@iae.nl (Marcel Hendrix) - 2012-08-27 20:45 +0200
                                Re: continue equivalent in Forth? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2012-08-27 21:43 +0100
                                Re: continue equivalent in Forth? "Elizabeth D. Rather" <erather@forth.com> - 2012-08-27 12:15 -1000
                                  Re: continue equivalent in Forth? mhx@iae.nl (Marcel Hendrix) - 2012-08-28 20:43 +0200
                                    Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-29 17:10 +1000
                                Re: continue equivalent in Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-28 15:56 +0000
                                  Re: continue equivalent in Forth? mhx@iae.nl (Marcel Hendrix) - 2012-08-28 20:35 +0200
                                    Re: continue equivalent in Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-30 12:32 +0000
                                      Re: continue equivalent in Forth? mhx@iae.nl (Marcel Hendrix) - 2012-08-30 22:39 +0200
                                        Re: continue equivalent in Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-31 09:14 +0000
                                          Re: continue equivalent in Forth? mhx@iae.nl (Marcel Hendrix) - 2012-08-31 21:32 +0200
                                            Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-09-02 20:30 +1000
                                            Re: continue equivalent in Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-09-02 13:15 +0000
                                    Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-31 18:27 +1000
                                      Re: continue equivalent in Forth? mhx@iae.nl (Marcel Hendrix) - 2012-08-31 20:39 +0200
                                        Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-09-01 14:28 +1000
            Re: continue equivalent in Forth? hughaguilar96@yahoo.com - 2012-08-21 22:59 -0700
          Re: continue equivalent in Forth? Bernd Paysan <bernd.paysan@gmx.de> - 2012-08-21 20:49 +0200
            Re: continue equivalent in Forth? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-22 07:46 -0400
              Re: continue equivalent in Forth? Bernd Paysan <bernd.paysan@gmx.de> - 2012-08-22 16:24 +0200
      Re: continue equivalent in Forth? programmingkidx@gmail.com - 2012-08-19 14:37 -0700
        Re: continue equivalent in Forth? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-08-20 05:17 -0500
        Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-20 22:34 +1000
        Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-20 23:01 +1000
        Re: continue equivalent in Forth? stephenXXX@mpeforth.com (Stephen Pelc) - 2012-08-21 08:34 +0000
          Re: continue equivalent in Forth? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2012-08-21 15:53 +0100
    Re: continue equivalent in Forth? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-19 11:00 -0400
      Re: continue equivalent in Forth? Coos Haak <chforth@hccnet.nl> - 2012-08-19 20:29 +0200
        Re: continue equivalent in Forth? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-21 00:04 -0400
      Re: continue equivalent in Forth? programmingkidx@gmail.com - 2012-08-19 14:09 -0700
    Re: continue equivalent in Forth? Mark Wills <markrobertwills@yahoo.co.uk> - 2012-08-19 11:31 -0700
      Re: continue equivalent in Forth? programmingkidx@gmail.com - 2012-08-19 14:43 -0700

Page 1 of 5  [1] 2 3 4 5  Next page →


#15025 — continue equivalent in Forth?

Fromprogrammingkidx@gmail.com
Date2012-08-18 19:28 -0700
Subjectcontinue equivalent in Forth?
Message-ID<8cbd2bb8-ed3d-4fab-a1da-af77293ecbb9@googlegroups.com>
When I am in a begin-while-repeat loop, I sometimes would like to go to the top of the loop. The "continue" keyword in C is what would help me perfectly here. Is there a "continue" like word in Forth? 

[toc] | [next] | [standalone]


#15027

FromAndrew Haley <andrew29@littlepinkcloud.invalid>
Date2012-08-19 01:43 -0500
Message-ID<-vqdnbtn6f2eFq3NnZ2dnUVZ7tCdnZ2d@supernews.com>
In reply to#15025
programmingkidx@gmail.com wrote:

> When I am in a begin-while-repeat loop, I sometimes would like to go
> to the top of the loop. The "continue" keyword in C is what would
> help me perfectly here. Is there a "continue" like word in Forth?

There's no exact equivalent, although any loop strucure can be written
in Forth.  If you can give us an example of what sort of thing you'd
like to write, we can show how it'd be done in Forth.  I'm a bit
concerned that the words you're trying to write may be too long: the
Forth way is to make them as short as possible and push the complexity
into words that are called.

Andrew.

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


#15029

Frommhx@iae.nl
Date2012-08-19 03:40 -0700
Message-ID<749d770b-3f90-4d3f-8463-35f2412b4400@googlegroups.com>
In reply to#15025
On Sunday, August 19, 2012 4:28:42 AM UTC+2, (unknown) wrote:
> When I am in a begin-while-repeat loop, I sometimes 
> would like to go to the top of the loop. The "continue" 
> keyword in C is what would help me perfectly here. 
> Is there a "continue" like word in Forth?

When the application is properly factored, one doesn't
encounter the need that often.

-- C --------------

    for (p = SE_SUN; p <= SE_CHIRON; p++) {
      if (p == SE_EARTH) continue;		
      // do the coordinate calculation for this planet p 
      iflgret = swe_calc_ut(tjd_ut, p, iflag, x2, serr);
	       
      if (iflgret < 0) // if there is a problem, a negative value is returned 
      					// and an error message is in serr. 
	 printf("error: %s\n", serr);	// get the name of the planet p 
      swe_get_planet_name(p, snam); 	// print the coordinates 
      printf("%10s\t%11.7f\t%10.7f\t%10.7f\t%10.7f\n", 
                 snam, x2[0], x2[1], x2[2], x2[3]); }

-- Forth --------------

: CALCULATE ( planet -- ) ( F: julday -- )
  DUP SE_EARTH = IF  DROP FDROP EXIT  ENDIF
  ... ;

: DEMO ( year month day -- )
  ...
  SE_CHIRON 1+ SE_SUN ?DO  I julianday CALCULATE  LOOP ;

-marcel

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


#15030

From"Ed" <invalid@nospam.com>
Date2012-08-19 21:07 +1000
Message-ID<k0qh7a$iq9$1@speranza.aioe.org>
In reply to#15025
programmingkidx@gmail.com wrote:
> When I am in a begin-while-repeat loop, I sometimes would like to go to the top of the loop.
> The "continue" keyword in C is what would help me perfectly here. Is there a "continue" like
> word in Forth?

No, as generally it can be avoided.  Provide a sample of what it
is that you wish to do and someone should be able to help.

That said, some forths have tools that allow one to implement
features found in other languages e.g.


: BEGIN
  postpone begin  0 cs-pick  cs-push ; immediate

: REPEAT
  cs-pop  cs-drop  postpone repeat ; immediate

: CONTINUE
  cs-pop  0 cs-pick  postpone again  cs-push ; immediate


: test ( -- )
  cr cr ." Chars b d f will be ignored, ESC quits." cr
  begin
    cr ." Enter character> "  key dup 27 -
  while ( not ESC )
    dup [char] b = if  drop continue  then
    dup [char] d = if  drop continue  then
    dup [char] f = if  drop continue  then
    ( char ) emit
  repeat  drop ;

test

Chars b d f will be ignored, ESC quits.

Enter character> a
Enter character>
Enter character> c
Enter character>
Enter character> e
Enter character>
Enter character> g
Enter character> h
Enter character> i
Enter character> j
Enter character>  ok



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


#15031

FromCoos Haak <chforth@hccnet.nl>
Date2012-08-19 13:55 +0200
Message-ID<1blibbkd9xioe.1opolnpg0wus5$.dlg@40tude.net>
In reply to#15030
Op Sun, 19 Aug 2012 21:07:12 +1000 schreef Ed:

> programmingkidx@gmail.com wrote:
>> When I am in a begin-while-repeat loop, I sometimes would like to go to the top of the loop.
>> The "continue" keyword in C is what would help me perfectly here. Is there a "continue" like
>> word in Forth?
> 
> No, as generally it can be avoided.  Provide a sample of what it
> is that you wish to do and someone should be able to help.
> 
> That said, some forths have tools that allow one to implement
> features found in other languages e.g.
> 
> 
>: BEGIN
>   postpone begin  0 cs-pick  cs-push ; immediate
> 
>: REPEAT
>   cs-pop  cs-drop  postpone repeat ; immediate
> 
>: CONTINUE
>   cs-pop  0 cs-pick  postpone again  cs-push ; immediate
> 
Some implementations may have similar constructs, but what does a beginner
do with such strange words like CS-PUSH, CS-POP, or CS-DROP? He _may_ have
CS-PICK and CS-ROLL from the Tools Extensions Wordlist, but how can he
implement the other three?
CS-DROP may sometimes be DROP, another time 2DROP or even 3DROP.

-- 
Coos

CHForth, 16 bit DOS applications
http://home.hccnet.nl/j.j.haak/forth.html 

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


#15048

From"Ed" <invalid@nospam.com>
Date2012-08-20 22:13 +1000
Message-ID<k0t9vi$k5d$1@speranza.aioe.org>
In reply to#15031
Coos Haak wrote:
> ...
> Some implementations may have similar constructs, but what does a beginner
> do with such strange words like CS-PUSH, CS-POP, or CS-DROP? He _may_ have
> CS-PICK and CS-ROLL from the Tools Extensions Wordlist, but how can he
> implement the other three?

I'm told the Standard is a minimum specification.


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


#15032

FromCoos Haak <chforth@hccnet.nl>
Date2012-08-19 14:18 +0200
Message-ID<ynvo412dq30u$.hnqbz7gjsjis$.dlg@40tude.net>
In reply to#15030
Op Sun, 19 Aug 2012 21:07:12 +1000 schreef Ed:

>: BEGIN
>   postpone begin  0 cs-pick  cs-push ; immediate
> 
>: REPEAT
>   cs-pop  cs-drop  postpone repeat ; immediate
> 
>: CONTINUE
>   cs-pop  0 cs-pick  postpone again  cs-push ; immediate
> 
> 
>: test ( -- )
>   cr cr ." Chars b d f will be ignored, ESC quits." cr
>   begin
>     cr ." Enter character> "  key dup 27 -
>   while ( not ESC )
>     dup [char] b = if  drop continue  then
>     dup [char] d = if  drop continue  then
>     dup [char] f = if  drop continue  then
>     ( char ) emit
>   repeat  drop ;

A much simpler solution with standard words, as IF adds one control level
above BEGIN:

: CONTINUE 1 CS-PICK POSTPONE AGAIN ; IMMEDIATE

-- 
Coos

CHForth, 16 bit DOS applications
http://home.hccnet.nl/j.j.haak/forth.html 

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


#15033

Frommhx@iae.nl (Marcel Hendrix)
Date2012-08-19 14:57 +0200
Message-ID<70788916958435@frunobulax.edu>
In reply to#15032
Coos Haak <chforth@hccnet.nl> writes Re: continue equivalent in Forth?

> Op Sun, 19 Aug 2012 21:07:12 +1000 schreef Ed:
[..]
> A much simpler solution with standard words, as IF adds one control level
> above BEGIN:

> : CONTINUE 1 CS-PICK POSTPONE AGAIN ; IMMEDIATE

It works in iForth (to my big surprise), given  SECURE OFF  .

FORTH> see test
Flags: ANSI
$01249680  : test
$0124968A  push          $01247268 d#
$0124968F  push          #45 b#
$01249691  lea           rbp, [rbp -8 +] qword
$01249695  mov           [rbp 0 +] qword, $012496A2 d#
$0124969D  jmp           TYPE+10 ( $01139042 ) offset NEAR
$012496A2  pop           rbx
$012496A3  lea           rax, [rax 0 +] qword
$012496A8  push          rbx
\ begin
$012496A9  push          $01247298 d#
$012496AE  push          #19 b#
$012496B0  lea           rbp, [rbp -8 +] qword
$012496B4  mov           [rbp 0 +] qword, $012496C1 d#
$012496BC  jmp           TYPE+10 ( $01139042 ) offset NEAR
$012496C1  lea           rbp, [rbp -8 +] qword
$012496C5  mov           [rbp 0 +] qword, $012496D2 d#
$012496CD  jmp           KEY+10 ( $01138FBA ) offset NEAR
$012496D2  pop           rbx
$012496D3  lea           rdi, [rbx #-27 +] qword
$012496D7  cmp           rdi, 0 b#
$012496DB  je            $0124972E offset NEAR
$012496E1  cmp           rbx, #98 b#
$012496E5  jne           $012496F1 offset NEAR
$012496EB  mov           rbx, [rsp] qword
$012496EF  jmp           $012496A9 offset SHORT   \ begin
$012496F1  cmp           rbx, #100 b#
$012496F5  jne           $01249701 offset NEAR
$012496FB  mov           rbx, [rsp] qword
$012496FF  jmp           $012496A9 offset SHORT   \ begin
$01249701  cmp           rbx, #102 b#
$01249705  jne           $01249711 offset NEAR
$0124970B  mov           rbx, [rsp] qword
$0124970F  jmp           $012496A9 offset SHORT   \ begin
$01249711  push          rbx
$01249712  lea           rbp, [rbp -8 +] qword
$01249716  mov           [rbp 0 +] qword, $01249723 d#
$0124971E  jmp           EMIT+10 ( $01139012 ) offset NEAR
$01249723  mov           rbx, [rsp] qword
$01249727  jmp           $012496A9 offset NEAR    \ begin
$0124972C  push          rbx
$0124972D  pop           rbx
$0124972E  ;

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


#15034

FromCoos Haak <chforth@hccnet.nl>
Date2012-08-19 16:39 +0200
Message-ID<q1i5pf9li64l$.6thzosx7b516$.dlg@40tude.net>
In reply to#15033
Op Sun, 19 Aug 2012 14:57:33 +0200 schreef Marcel Hendrix:

> Coos Haak <chforth@hccnet.nl> writes Re: continue equivalent in Forth?
> 
>> Op Sun, 19 Aug 2012 21:07:12 +1000 schreef Ed:
> [..]
>> A much simpler solution with standard words, as IF adds one control level
>> above BEGIN:
> 
>>: CONTINUE 1 CS-PICK POSTPONE AGAIN ; IMMEDIATE
> 
> It works in iForth (to my big surprise), given  SECURE OFF  .

Of course, look at your own Ackermann benchmarks of some decades ago!

-- 
Coos

CHForth, 16 bit DOS applications
http://home.hccnet.nl/j.j.haak/forth.html 

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


#15049

From"Ed" <invalid@nospam.com>
Date2012-08-20 22:18 +1000
Message-ID<k0t9vl$k5d$2@speranza.aioe.org>
In reply to#15032
Coos Haak wrote:
> ...
> A much simpler solution with standard words, as IF adds one control level
> above BEGIN:
>
> : CONTINUE 1 CS-PICK POSTPONE AGAIN ; IMMEDIATE

Real-world apps may not be so accommodating.


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


#15064

From"Rod Pemberton" <do_not_have@notemailnot.cmm>
Date2012-08-21 00:05 -0400
Message-ID<k0v1ag$imu$1@speranza.aioe.org>
In reply to#15032
"Coos Haak" <chforth@hccnet.nl> wrote in message
news:ynvo412dq30u$.hnqbz7gjsjis$.dlg@40tude.net...
> Op Sun, 19 Aug 2012 21:07:12 +1000 schreef Ed:
>
> >: BEGIN
> >   postpone begin  0 cs-pick  cs-push ; immediate
> >
> >: REPEAT
> >   cs-pop  cs-drop  postpone repeat ; immediate
> >
> >: CONTINUE
> >   cs-pop  0 cs-pick  postpone again  cs-push ; immediate
> >
> >
> >: test ( -- )
> >   cr cr ." Chars b d f will be ignored, ESC quits." cr
> >   begin
> >     cr ." Enter character> "  key dup 27 -
> >   while ( not ESC )
> >     dup [char] b = if  drop continue  then
> >     dup [char] d = if  drop continue  then
> >     dup [char] f = if  drop continue  then
> >     ( char ) emit
> >   repeat  drop ;
>
> A much simpler solution with standard words, as IF adds one control level
> above BEGIN:
>
> : CONTINUE 1 CS-PICK POSTPONE AGAIN ; IMMEDIATE
>

A separate control-flow stack isn't a requirement for ANS compliance.  So,
AISI, this definition for CONTINUE will only work if the Forth in question
has a control-flow stack separate from the data stack, or the implementation
uses a data stack for both and then tracks control-flow data somehow.  I
think the latter would complicate CS-ROLL and CS-PICK immensely.

AIUI, most Forths don't have a control-flow stack separate from the
parameter or data stack.  They use the data stack for both.  Such a simple
definition for CONTINUE will not work in such a case since BEGIN's address
could be below other stacked data.  I.e., how do you locate which stack
location has BEGIN's address?


BEGIN
\ BEGIN's address on data stack
   ... \ other data on stack
\ how does CONTINUE get BEGIN's address here?
   IF CONTINUE THEN
   ...
WHILE
   ...
   IF CONTINUE THEN
   ...
REPEAT


Rod Pemberton


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


#15065

Fromhughaguilar96@yahoo.com
Date2012-08-20 21:17 -0700
Message-ID<4be1e023-d0a8-464a-a8f2-08943bbf5cf3@googlegroups.com>
In reply to#15064
On Monday, August 20, 2012 9:05:59 PM UTC-7, Rod Pemberton wrote:
> AIUI, most Forths don't have a control-flow stack separate from the
> parameter or data stack.  They use the data stack for both.  Such a simple
> definition for CONTINUE will not work in such a case since BEGIN's address
> could be below other stacked data.  I.e., how do you locate which stack
> location has BEGIN's address?

Straight Forth will require that the control-flow stack be separate from the data stack --- this is one of the many gross mistakes of ANS-Forth that will be corrected --- the control-flow stack is used at compile-time anyway, so speed is not an issue.

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


#15068

FromAlex McDonald <blog@rivadpm.com>
Date2012-08-21 02:40 -0700
Message-ID<87a8dea7-f028-43cc-bbdd-85388bffb2ec@t18g2000yqi.googlegroups.com>
In reply to#15065
On Aug 21, 5:17 am, hughaguila...@yahoo.com wrote:
> On Monday, August 20, 2012 9:05:59 PM UTC-7, Rod Pemberton wrote:
> > AIUI, most Forths don't have a control-flow stack separate from the
> > parameter or data stack.  They use the data stack for both.  Such a simple
> > definition for CONTINUE will not work in such a case since BEGIN's address
> > could be below other stacked data.  I.e., how do you locate which stack
> > location has BEGIN's address?
>
> Straight Forth will require that the control-flow stack be separate from the data stack --- this is one of the many gross mistakes of ANS-Forth that will be corrected --- the control-flow stack is used at compile-time anyway, so speed is not an issue.

Why is this a gross mistake, and what advantage does a separate
control stack bring?

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


#15082

From"Ed" <invalid@nospam.com>
Date2012-08-22 15:33 +1000
Message-ID<k11qpq$2c6$1@speranza.aioe.org>
In reply to#15065
hughaguilar96@yahoo.com wrote:
> On Monday, August 20, 2012 9:05:59 PM UTC-7, Rod Pemberton wrote:
> > AIUI, most Forths don't have a control-flow stack separate from the
> > parameter or data stack.  They use the data stack for both.  Such a simple
> > definition for CONTINUE will not work in such a case since BEGIN's address
> > could be below other stacked data.  I.e., how do you locate which stack
> > location has BEGIN's address?
>
> Straight Forth will require that the control-flow stack be separate from the data stack ---
> this is one of the many gross mistakes of ANS-Forth that will be corrected --- the
> control-flow stack is used at compile-time anyway, so speed is not an issue.

The creator of the control-flow-stack (or documentor as he prefers to say)
believed Forth had all control structures it needed.  His purpose in introducing
a cfs and associated words was very specific.  Below he explains what it was
intended for and the political compromises he needed to make:

quote

    Newsgroups: comp.lang.forth
    From: wilba...@netcom.com (Wil Baden)
    Date: 1998/10/27
    Subject: Re: Does LEAVE need its own dedicated stack?

    As the one who created and proposed `CS-ROLL`, `CS-PICK`, `AHEAD`, and
    `UNLOOP` (my names were changed), and proposed the behavior of `WHILE`,
    this thread brings back old memories.

    `CS-ROLL` and `CS-PICK` are not intended for writing programs.  They are
    guarantees.  They guarantee that any control-flow logic with `GOTO`s, no
    matter how messy, can be written in Forth.  `CS-PICK` isn't necessary.  The
    conversion is mechanical.  With a depth first search, most programs written
    with `GOTO`s can be converted to strictly structured.  In fact most uses of
    unstructured logic can be rewritten with just one form of `CS-ROLL`.

    [...]

    There were two main parties at that time.

    1.  We don't need control flow syntax checking and so want only
    one cell for a control-flow stack element.

    2.  We should have control flow syntax checking and so we must
    have two cells for a control-flow stack element.

    The concept of control-stack was introduced to solve the problem of
    control-flow stack size.  I didn't invent the control-flow stack: I
    named it and documented it.

    The control-flow stack was also to pacify those who thought the data
    stack shouldn't be used for control-flow words.

    To me that is silly.  The data stack has no good use during compilation and
    to have a special stack only used during compilation is foolish, especially
    in multi-user systems.

end-quote

I don't use a separate CFS stack.  In fact I rarely use the extension words
I implemented.  But they're fun to have and (if using the data stack) cheap
to implement.


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


#15067

FromAlex McDonald <blog@rivadpm.com>
Date2012-08-21 02:37 -0700
Message-ID<a2f22ce8-ab03-4006-872e-9a6cc2ebc6c0@k3g2000vby.googlegroups.com>
In reply to#15064
On Aug 21, 5:05 am, "Rod Pemberton" <do_not_h...@notemailnot.cmm>
wrote:
> "Coos Haak" <chfo...@hccnet.nl> wrote in message
>
> news:ynvo412dq30u$.hnqbz7gjsjis$.dlg@40tude.net...
>
>
>
>
>
>
>
>
>
> > Op Sun, 19 Aug 2012 21:07:12 +1000 schreef Ed:
>
> > >: BEGIN
> > >   postpone begin  0 cs-pick  cs-push ; immediate
>
> > >: REPEAT
> > >   cs-pop  cs-drop  postpone repeat ; immediate
>
> > >: CONTINUE
> > >   cs-pop  0 cs-pick  postpone again  cs-push ; immediate
>
> > >: test ( -- )
> > >   cr cr ." Chars b d f will be ignored, ESC quits." cr
> > >   begin
> > >     cr ." Enter character> "  key dup 27 -
> > >   while ( not ESC )
> > >     dup [char] b = if  drop continue  then
> > >     dup [char] d = if  drop continue  then
> > >     dup [char] f = if  drop continue  then
> > >     ( char ) emit
> > >   repeat  drop ;
>
> > A much simpler solution with standard words, as IF adds one control level
> > above BEGIN:
>
> > : CONTINUE 1 CS-PICK POSTPONE AGAIN ; IMMEDIATE
>
> A separate control-flow stack isn't a requirement for ANS compliance.  So,
> AISI, this definition for CONTINUE will only work if the Forth in question
> has a control-flow stack separate from the data stack, or the implementation
> uses a data stack for both and then tracks control-flow data somehow.  I
> think the latter would complicate CS-ROLL and CS-PICK immensely.
>
> AIUI, most Forths don't have a control-flow stack separate from the
> parameter or data stack.  They use the data stack for both.  Such a simple
> definition for CONTINUE will not work in such a case since BEGIN's address
> could be below other stacked data.  I.e., how do you locate which stack
> location has BEGIN's address?
>
> BEGIN
> \ BEGIN's address on data stack
>    ... \ other data on stack
> \ how does CONTINUE get BEGIN's address here?
>    IF CONTINUE THEN
>    ...
> WHILE
>    ...
>    IF CONTINUE THEN
>    ...
> REPEAT
>
> Rod Pemberton

You're confusing what happens at compile time with what happens at run
time. At compile time, when the compiler hits the CONTINUE in BEGIN
( various words like @ DUP etc ) IF CONTINUE THEN ... the stack
contains;

  <begin-addr> <if-addr>

and 1 CS-PICK pulls off <begin-addr>. There's nothing from run time
( various words like @ DUP etc ) on the stack because we're
compiling.

At run time, there's no control flow on the stack. Hence the data
stack and the control stack can be the same stack. The code works
regardless of how the control stack is implemented.

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


#15079

From"Rod Pemberton" <do_not_have@notemailnot.cmm>
Date2012-08-22 00:53 -0400
Message-ID<k11of2$s59$1@speranza.aioe.org>
In reply to#15067
"Alex McDonald" <blog@rivadpm.com> wrote in message
news:a2f22ce8-ab03-4006-872e-9a6cc2ebc6c0@k3g2000vby.googlegroups.com...
> On Aug 21, 5:05 am, "Rod Pemberton" <do_not_h...@notemailnot.cmm>
> wrote:
> > "Coos Haak" <chfo...@hccnet.nl> wrote in message
> > news:ynvo412dq30u$.hnqbz7gjsjis$.dlg@40tude.net...
> > > Op Sun, 19 Aug 2012 21:07:12 +1000 schreef Ed:
...

> > > >: BEGIN
> > > > postpone begin 0 cs-pick cs-push ; immediate
>
> > > >: REPEAT
> > > > cs-pop cs-drop postpone repeat ; immediate
>
> > > >: CONTINUE
> > > > cs-pop 0 cs-pick postpone again cs-push ; immediate
>
> > > >: test ( -- )
> > > > cr cr ." Chars b d f will be ignored, ESC quits." cr
> > > > begin
> > > > cr ." Enter character> " key dup 27 -
> > > > while ( not ESC )
> > > > dup [char] b = if drop continue then
> > > > dup [char] d = if drop continue then
> > > > dup [char] f = if drop continue then
> > > > ( char ) emit
> > > > repeat drop ;
>
> > > A much simpler solution with standard words, as IF adds
> > > one control level above BEGIN:
>
> > > : CONTINUE 1 CS-PICK POSTPONE AGAIN ; IMMEDIATE
>
> > A separate control-flow stack isn't a requirement for ANS compliance.
So,
> > AISI, this definition for CONTINUE will only work if the Forth in
question
> > has a control-flow stack separate from the data stack, or the
implementation
> > uses a data stack for both and then tracks control-flow data somehow. I
> > think the latter would complicate CS-ROLL and CS-PICK immensely.
>
> > AIUI, most Forths don't have a control-flow stack separate from the
> > parameter or data stack. They use the data stack for both. Such a simple
> > definition for CONTINUE will not work in such a case since BEGIN's
address
> > could be below other stacked data. I.e., how do you locate which stack
> > location has BEGIN's address?
>
> > BEGIN
> > \ BEGIN's address on data stack
> > ... \ other data on stack
> > \ how does CONTINUE get BEGIN's address here?
> > IF CONTINUE THEN
> > ...
> > WHILE
> > ...
> > IF CONTINUE THEN
> > ...
> > REPEAT
>
>
> You're confusing what happens at compile time with what happens at run
> time.

I think the issue affects use of control words placing data on the stack
too.

> At compile time, when the compiler hits the CONTINUE in BEGIN
> ( various words like @ DUP etc ) IF CONTINUE THEN ... the stack
> contains;
>
>   <begin-addr> <if-addr>
>
> and 1 CS-PICK pulls off <begin-addr>. There's nothing from run time
> ( various words like @ DUP etc ) on the stack because we're
> compiling.

That requires that CONTINUE be used within a single IF-THEN.  I.e., what if
there are two <if-addr>'s on the stack?

> At run time, there's no control flow on the stack. Hence the data
> stack and the control stack can be the same stack.

True.

> The code works
> regardless of how the control stack is implemented.

Yeah, I don't think so...


Rod Pemberton

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


#15089

FromAlex McDonald <blog@rivadpm.com>
Date2012-08-22 04:10 -0700
Message-ID<8f2cea0e-50de-4d14-a2ed-73d08e15fc75@ft6g2000vbb.googlegroups.com>
In reply to#15079
On Aug 22, 5:53 am, "Rod Pemberton" <do_not_h...@notemailnot.cmm>
wrote:
> "Alex McDonald" <b...@rivadpm.com> wrote in message
>
> news:a2f22ce8-ab03-4006-872e-9a6cc2ebc6c0@k3g2000vby.googlegroups.com...> On Aug 21, 5:05 am, "Rod Pemberton" <do_not_h...@notemailnot.cmm>
> > wrote:
> > > "Coos Haak" <chfo...@hccnet.nl> wrote in message
> > >news:ynvo412dq30u$.hnqbz7gjsjis$.dlg@40tude.net...
> > > > Op Sun, 19 Aug 2012 21:07:12 +1000 schreef Ed:
>
> ...
>
>
>
>
>
>
>
>
>
>
>
> > > > >: BEGIN
> > > > > postpone begin 0 cs-pick cs-push ; immediate
>
> > > > >: REPEAT
> > > > > cs-pop cs-drop postpone repeat ; immediate
>
> > > > >: CONTINUE
> > > > > cs-pop 0 cs-pick postpone again cs-push ; immediate
>
> > > > >: test ( -- )
> > > > > cr cr ." Chars b d f will be ignored, ESC quits." cr
> > > > > begin
> > > > > cr ." Enter character> " key dup 27 -
> > > > > while ( not ESC )
> > > > > dup [char] b = if drop continue then
> > > > > dup [char] d = if drop continue then
> > > > > dup [char] f = if drop continue then
> > > > > ( char ) emit
> > > > > repeat drop ;
>
> > > > A much simpler solution with standard words, as IF adds
> > > > one control level above BEGIN:
>
> > > > : CONTINUE 1 CS-PICK POSTPONE AGAIN ; IMMEDIATE
>
> > > A separate control-flow stack isn't a requirement for ANS compliance.
> So,
> > > AISI, this definition for CONTINUE will only work if the Forth in
> question
> > > has a control-flow stack separate from the data stack, or the
> implementation
> > > uses a data stack for both and then tracks control-flow data somehow. I
> > > think the latter would complicate CS-ROLL and CS-PICK immensely.
>
> > > AIUI, most Forths don't have a control-flow stack separate from the
> > > parameter or data stack. They use the data stack for both. Such a simple
> > > definition for CONTINUE will not work in such a case since BEGIN's
> address
> > > could be below other stacked data. I.e., how do you locate which stack
> > > location has BEGIN's address?
>
> > > BEGIN
> > > \ BEGIN's address on data stack
> > > ... \ other data on stack
> > > \ how does CONTINUE get BEGIN's address here?
> > > IF CONTINUE THEN
> > > ...
> > > WHILE
> > > ...
> > > IF CONTINUE THEN
> > > ...
> > > REPEAT
>
> > You're confusing what happens at compile time with what happens at run
> > time.
>
> I think the issue affects use of control words placing data on the stack
> too.
>
> > At compile time, when the compiler hits the CONTINUE in BEGIN
> > ( various words like @ DUP etc ) IF CONTINUE THEN ... the stack
> > contains;
>
> >   <begin-addr> <if-addr>
>
> > and 1 CS-PICK pulls off <begin-addr>. There's nothing from run time
> > ( various words like @ DUP etc ) on the stack because we're
> > compiling.
>
> That requires that CONTINUE be used within a single IF-THEN.  I.e., what if
> there are two <if-addr>'s on the stack?

Coos noted that in his submission. It's up to you as a programmer to
take heed.

>
> > At run time, there's no control flow on the stack. Hence the data
> > stack and the control stack can be the same stack.
>
> True.
>
> > The code works
> > regardless of how the control stack is implemented.
>
> Yeah, I don't think so...
>
> Rod Pemberton

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


#15069

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2012-08-21 11:40 +0000
Message-ID<2012Aug21.134016@mips.complang.tuwien.ac.at>
In reply to#15064
"Rod Pemberton" <do_not_have@notemailnot.cmm> writes:
>"Coos Haak" <chforth@hccnet.nl> wrote in message
>news:ynvo412dq30u$.hnqbz7gjsjis$.dlg@40tude.net...
>> : CONTINUE 1 CS-PICK POSTPONE AGAIN ; IMMEDIATE
[...]
>AIUI, most Forths don't have a control-flow stack separate from the
>parameter or data stack.  They use the data stack for both.  Such a simple
>definition for CONTINUE will not work in such a case since BEGIN's address
>could be below other stacked data.

What other stacked data?  The only data usually on the stack above
colon-sys during compilation are control-flow stack items.  That's why
it's practical to use the data stack as control-flow stack.  If people
put data on the stack during compilation that lived across
control-flow words, not just CONTINUE would be in trouble, but every
other control-flow word, too.  But they don't.

>BEGIN
>\ BEGIN's address on data stack
>   ... \ other data on stack
>\ how does CONTINUE get BEGIN's address here?
>   IF CONTINUE THEN

Simple: There are only control-flow stack items there, and it's the
second control-flow stack item.

>   ...
>WHILE
>   ...
>   IF CONTINUE THEN
>   ...
>REPEAT

You could also ask how REPEAT gets BEGIN's address here.  The answer
is the same.

- 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 2012: http://www.euroforth.org/ef12/

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


#15080

From"Rod Pemberton" <do_not_have@notemailnot.cmm>
Date2012-08-22 00:53 -0400
Message-ID<k11oga$s79$1@speranza.aioe.org>
In reply to#15069
"Anton Ertl" <anton@mips.complang.tuwien.ac.at> wrote in message
news:2012Aug21.134016@mips.complang.tuwien.ac.at...
> "Rod Pemberton" <do_not_have@notemailnot.cmm> writes:
> >"Coos Haak" <chforth@hccnet.nl> wrote in message
> >news:ynvo412dq30u$.hnqbz7gjsjis$.dlg@40tude.net...
...

> >> : CONTINUE 1 CS-PICK POSTPONE AGAIN ; IMMEDIATE
> [...]
> >AIUI, most Forths don't have a control-flow stack separate from the
> >parameter or data stack.  They use the data stack for both.  Such a
> >simple definition for CONTINUE will not work in such a case since
> >BEGIN's address could be below other stacked data.
>
> What other stacked data?  The only data usually on the stack above
> colon-sys during compilation are control-flow stack items.  That's why
> it's practical to use the data stack as control-flow stack.  If people
> put data on the stack during compilation that lived across
> control-flow words, not just CONTINUE would be in trouble, but every
> other control-flow word, too.  But they don't.
>

Aren't you ignoring the fact that there could be other control words placing
data on the stack?  E.g., what if COTINUE is used within nested IF-THENs.
CONTINUE as Coos coded it requires that the address it uses be in a specific
stack position.  However, the programmer determines which control words and
how many come prior to it's use.  Are you going to modify all control words,
similar to WHILE, to preserve that location just to use CONTINUE?


Rod Pemberton



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


#15084

From"Elizabeth D. Rather" <erather@forth.com>
Date2012-08-21 21:18 -1000
Message-ID<he6dnab1PPQjGqnNnZ2dnUVZ_u-dnZ2d@supernews.com>
In reply to#15080
On 8/21/12 6:53 PM, Rod Pemberton wrote:
> "Anton Ertl" <anton@mips.complang.tuwien.ac.at> wrote in message
> news:2012Aug21.134016@mips.complang.tuwien.ac.at...
>> "Rod Pemberton" <do_not_have@notemailnot.cmm> writes:
>>> "Coos Haak" <chforth@hccnet.nl> wrote in message
>>> news:ynvo412dq30u$.hnqbz7gjsjis$.dlg@40tude.net...
> ...
>
>>>> : CONTINUE 1 CS-PICK POSTPONE AGAIN ; IMMEDIATE
>> [...]
>>> AIUI, most Forths don't have a control-flow stack separate from the
>>> parameter or data stack.  They use the data stack for both.  Such a
>>> simple definition for CONTINUE will not work in such a case since
>>> BEGIN's address could be below other stacked data.
>>
>> What other stacked data?  The only data usually on the stack above
>> colon-sys during compilation are control-flow stack items.  That's why
>> it's practical to use the data stack as control-flow stack.  If people
>> put data on the stack during compilation that lived across
>> control-flow words, not just CONTINUE would be in trouble, but every
>> other control-flow word, too.  But they don't.
>>
>
> Aren't you ignoring the fact that there could be other control words placing
> data on the stack?  E.g., what if COTINUE is used within nested IF-THENs.
> CONTINUE as Coos coded it requires that the address it uses be in a specific
> stack position.  However, the programmer determines which control words and
> how many come prior to it's use.  Are you going to modify all control words,
> similar to WHILE, to preserve that location just to use CONTINUE?

If your control-flow is that complicated, you need to factor differently.

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]


Page 1 of 5  [1] 2 3 4 5  Next page →

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


csiph-web