Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #30533 > unrolled thread
| Started by | David J <skamolex@gmail.com> |
|---|---|
| First post | 2014-05-21 13:44 -0700 |
| Last post | 2014-06-28 14:00 -0700 |
| Articles | 20 on this page of 88 — 20 participants |
Back to article view | Back to comp.lang.forth
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 3 of 5 — ← Prev page 1 2 [3] 4 5 Next page →
| From | ForthFreak <forthfreak@gmail.com> |
|---|---|
| Date | 2014-05-25 02:03 -0700 |
| Message-ID | <b312bcb3-4958-44a4-84e9-6c1841e98240@googlegroups.com> |
| In reply to | #30660 |
Clyde's reply on 24 May seems to be the closest solution to the OP's question, however, the OP wanted to start processing the list of words from the BEGINNING again when an exit/exception condition was detected.
A small addition to Clyde's solution provides that exact behaviour:
: ?EXIT ( f -- ) IF R> DROP THEN ;
: DoMe1rst ( -- f )
CR ." A" CR
0 ( -- f = CONTINUE ) ;
: DoMe2nd ( -- f )
CR ." B" CR
1 ( -- f = STOP HERE ) ;
: DoMe3rd ( -- f )
CR ." C" CR
0 ( -- f = CONTINUE ) ;
: TS
BEGIN
DoMe1rst ?EXIT
DoMe2nd ?EXIT ( SHOULD PRINT A and B and not C )
DoMe3rd ( unless you use AGAIN )
( The flag is handled by until here! )
UNTIL
;
: FOREVER
BEGIN
TS
AGAIN ;
(continually displays A B A B A B A B etc...)
[toc] | [prev] | [next] | [standalone]
| From | rickman <gnuarm@gmail.com> |
|---|---|
| Date | 2014-05-25 05:18 -0400 |
| Message-ID | <llscge$kkt$1@dont-email.me> |
| In reply to | #30682 |
On 5/25/2014 5:03 AM, ForthFreak wrote: > Clyde's reply on 24 May seems to be the closest solution to the OP's question, however, the OP wanted to start processing the list of words from the BEGINNING again when an exit/exception condition was detected. > > A small addition to Clyde's solution provides that exact behaviour: > > : ?EXIT ( f -- ) IF R> DROP THEN ; > > : DoMe1rst ( -- f ) > CR ." A" CR > 0 ( -- f = CONTINUE ) ; > > : DoMe2nd ( -- f ) > CR ." B" CR > 1 ( -- f = STOP HERE ) ; > > : DoMe3rd ( -- f ) > CR ." C" CR > 0 ( -- f = CONTINUE ) ; > > : TS > BEGIN > DoMe1rst ?EXIT > DoMe2nd ?EXIT ( SHOULD PRINT A and B and not C ) > DoMe3rd ( unless you use AGAIN ) > ( The flag is handled by until here! ) > UNTIL > ; > > : FOREVER > BEGIN > TS > AGAIN ; > > > (continually displays A B A B A B A B etc...) Except it has unneeded code. The BEGIN UNTIL of the TS word is not needed. Just include ?EXIT or DROP after DoMe3rd and omit the loop inside TS. Or was this intended to be an optimization of some sort? -- Rick
[toc] | [prev] | [next] | [standalone]
| From | ForthFreak <forthfreak@gmail.com> |
|---|---|
| Date | 2014-05-25 03:01 -0700 |
| Message-ID | <b5f8d5c5-70c2-4a9c-b72d-0ef6baed1409@googlegroups.com> |
| In reply to | #30683 |
Ah, yes, of course. Thanks Rick.
Corrected/improved:
: ?EXIT ( f -- ) IF R> DROP THEN ;
: DoMe1rst ( -- f )
CR ." A" CR
0 ( -- f = CONTINUE ) ;
: DoMe2nd ( -- f )
CR ." B" CR
1 ( -- f = STOP HERE ) ;
: DoMe3rd ( -- f )
CR ." C" CR
0 ( -- f = CONTINUE ) ;
: TS
DoMe1rst ?EXIT
DoMe2nd ?EXIT ( SHOULD PRINT A and B and not C )
DoMe3rd ?EXIT ( or DROP)
;
: FOREVER
BEGIN
TS
AGAIN ;
(tested on my Forth 83 system. Works fine)
[toc] | [prev] | [next] | [standalone]
| From | David J <skamolex@gmail.com> |
|---|---|
| Date | 2014-05-25 14:10 -0700 |
| Message-ID | <28f870ac-ede7-4571-8172-81ec87ca98fe@googlegroups.com> |
| In reply to | #30684 |
On Sunday, May 25, 2014 4:01:45 AM UTC-6, ForthFreak wrote: > Ah, yes, of course. Thanks Rick. > > > > Corrected/improved: > > > > : ?EXIT ( f -- ) IF R> DROP THEN ; > > > > : DoMe1rst ( -- f ) > > CR ." A" CR > > 0 ( -- f = CONTINUE ) ; > > > > : DoMe2nd ( -- f ) > > CR ." B" CR > > 1 ( -- f = STOP HERE ) ; > > > > : DoMe3rd ( -- f ) > > CR ." C" CR > > 0 ( -- f = CONTINUE ) ; > > > > : TS > > DoMe1rst ?EXIT > > DoMe2nd ?EXIT ( SHOULD PRINT A and B and not C ) > > DoMe3rd ?EXIT ( or DROP) > > ; > > > > : FOREVER > > BEGIN > > TS > > AGAIN ; > > > > (tested on my Forth 83 system. Works fine) Thank you FF, Rick, Clyde, and all! This is exactly what was/is needed. The embedded controller is expected to loop (or repeat or whatever-term-is-appropriate-and-unambiguous) 24/7 for the next 15 years. And ForthFreak is right...processing of the list has to return to the BEGINNING whenever one of the words in the list reports an exception.
[toc] | [prev] | [next] | [standalone]
| From | "Clyde W. Phillips Jr." <cwpjr02@gmail.com> |
|---|---|
| Date | 2014-05-25 15:19 -0700 |
| Message-ID | <b799dcee-d4ae-4252-85eb-4fc1aa174a67@googlegroups.com> |
| In reply to | #30718 |
Thanks you all! Cheers, Clyde
[toc] | [prev] | [next] | [standalone]
| From | Bee <forth@calcentral.com> |
|---|---|
| Date | 2014-05-25 10:13 -0700 |
| Message-ID | <5553d59a-af39-4534-8e5b-c8bb904bad32@googlegroups.com> |
| In reply to | #30533 |
On 5/22/2014 1:31 AM, David J wrote:
(I'd love to use Rick's first idea,
for example, but there is no EXIT.)
What version of Forth is it?
What is the threading mechanism?
+ indirect, direct, subroutine, bit-threaded
Does it have a word spelled 'SEMI'?
What is the action of ';' ?
On Sunday, May 25, 2014 3:01:45 AM UTC-7, ForthFreak wrote:
> Ah, yes, of course. Thanks Rick.
> Corrected/improved:
> : ?EXIT ( f -- ) IF R> DROP THEN ;
Using R> DROP like this is implementation dependent
(it will NOT work on some implementations)
and therefor should NOT be used.
The following now tested with gForth and SwiftForth on Linux.
\ .......1.........2.........3.........4.........5.........6....
: DoMe1 ( -- f ) ." a" 0 ( -- f = continue ) ;
: DoMe2 ( -- f ) ." b" 1 ( -- f = stop here ) ;
: DoMe3 ( -- f ) ." c" 0 ( -- f = continue ) ;
create taskList ( -- a )
' DoMe1 ,
' DoMe2 ,
' DoMe3 ,
( more tasks )
here
' taskList , ( non-zero dummy )
here swap - ( calculate cell size )
constant cell ( -- u )
0 [if] ( runtime version )
: taskLoop ( a -- )
cell - dup ( a a )
begin
begin cell + ( next in task list )
dup @ execute ( a a f )
until drop dup ( restart task list )
again ;
[else] ( test version )
: taskLoop ( a -- )
cell - dup ( a a )
begin
begin cell + ( next in task list )
dup @ execute ( a a f )
until drop dup ( restart task list )
space ( mark restart list )
key [char] q = ( pace output )
until 2drop ;
[then]
taskList taskLoop ( start task loop )
\ .......1.........2.........3.........4.........5.........6....
Bill
[toc] | [prev] | [next] | [standalone]
| From | David J <skamolex@gmail.com> |
|---|---|
| Date | 2014-05-25 15:22 -0700 |
| Message-ID | <badc15a0-cba1-4762-9701-f4e4d0a797f3@googlegroups.com> |
| In reply to | #30696 |
On Sunday, May 25, 2014 11:13:41 AM UTC-6, Bee wrote: > On 5/22/2014 1:31 AM, David J wrote: > > (I'd love to use Rick's first idea, > > for example, but there is no EXIT.) > > > > What version of Forth is it? > > What is the threading mechanism? > > + indirect, direct, subroutine, bit-threaded > > Does it have a word spelled 'SEMI'? > Bill, it's an embedded Forth that is resident in a memory-constrained microcontroller. Therefore the selection of words to include had to be carefully considered. As a consequence, it has no native SEMI or EXIT. And while cross-platform compatibility is a worthy goal, this particular project is so specialized, and coupled so tightly to the hardware on which it runs, that compatibility is probably one of the less important design criteria. As for indirect, direct, subroutine, or bit-threaded, I don't know. I know the core words are implemented in assembly language for speed.
[toc] | [prev] | [next] | [standalone]
| From | BruceMcF <agila61@netscape.net> |
|---|---|
| Date | 2014-06-12 13:11 -0700 |
| Message-ID | <29abb6bc-9f8c-414e-84e1-19dea80ef6a6@googlegroups.com> |
| In reply to | #30720 |
On Sunday, May 25, 2014 6:22:31 PM UTC-4, David J wrote:
> As for indirect, direct, subroutine, or bit-threaded, I don't know. I know the core words are implemented in assembly language for speed.
The key issue is whether it uses the R stack as the actual return stack, how the return address is stored, and whether the top of stack is the instruction pointer ~ in a common classical FORTH implementation, EXIT can be provided with:
: exit1 R> DROP ;
With returns two cells wide, its:
: exit2 2R> 2DROP ;
If the R is not the hardware return stack, your out of luck. But you can try EXIT2 with a word that is nested two deep, and if it exits two levels, you probably have a classical single-cell return value on stack.
: test-level3 ( index -- index- ) exit2 2+ ;
: test-level2 ( index -- index ) test-level3 1+ ;
: exit-test
CR CR ." --------------------------"
0 test-level2
DUP 0= IF
DROP CR ." Classic Forth R stack as return stack."
ELSE 1 = IF
CR ." Classic Forth R stack with return values double in size."
ELSE
CR ." Does not look like a classical R as return stack."
THEN
THEN CR CR CR CR ." --------------------------" CR CR ;
When I run that one gforth for Windows, it tests as a classic rack. The two results that test as something else are the "Does not look like" message or crashing or aborting the Forth compiler.
[toc] | [prev] | [next] | [standalone]
| From | David J <skamolex@gmail.com> |
|---|---|
| Date | 2014-06-12 19:06 -0700 |
| Message-ID | <3f8f52a4-6e15-4b92-87ea-8736fc8a355e@googlegroups.com> |
| In reply to | #31462 |
On Thursday, June 12, 2014 2:11:51 PM UTC-6, BruceMcF wrote: > On Sunday, May 25, 2014 6:22:31 PM UTC-4, David J wrote: > > As for indirect, direct, subroutine, or bit-threaded, I don't know. I know the core words are implemented in assembly language for speed. > > The key issue is whether it uses the R stack as the actual return stack, how the return address is stored, and whether the top of stack is the instruction pointer ~ in a common classical FORTH implementation, EXIT can be provided with: > > : exit1 R> DROP ; This solved the problem very well in FISH Forth. The design is finished and installed. It's been working 24/7 without the slightest glitch. I'm delighted with the platform, language, and everything else. Haven't had so much fun programming in a long time. :)
[toc] | [prev] | [next] | [standalone]
| From | BruceMcF <agila61@netscape.net> |
|---|---|
| Date | 2014-06-12 12:36 -0700 |
| Message-ID | <59197a5d-9e3b-47b1-bf85-d883081c21e0@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?
Could you do it with a state machine? Say its four operations, and the status returns are all TRUE for go on to the next and FALSE to start over from the beginning. Then end the state machine with a FALSE and it will go back to the beginning even if all four succeed.
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 ;
op-sequence run-machine
If you have CELL-COUNT that would be:
: run-machine ( a -- ) \ address of a structure with an op-sequence
>R BEGIN
R@ REPEAT CELL-COUNT EXECUTE 0= UNTIL DROP
AGAIN ;
[toc] | [prev] | [next] | [standalone]
| From | BruceMcF <agila61@netscape.net> |
|---|---|
| Date | 2014-06-12 19:50 -0700 |
| Message-ID | <e65928d9-46d9-464f-b67c-ace0fc8918cb@googlegroups.com> |
| In reply to | #31461 |
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 ;
[toc] | [prev] | [next] | [standalone]
| From | rickman <gnuarm@gmail.com> |
|---|---|
| Date | 2014-06-13 01:02 -0400 |
| Message-ID | <lne0l5$dt8$1@dont-email.me> |
| In reply to | #31468 |
On 6/12/2014 10:50 PM, 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 ;
: 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 ;
I'm just exploring my inner forth. I don't like to have nested loops
unless there is a need. In this case it lets you test the list word
without going into an infinite loop that requires a reset to exit.
I also think the dup cell+ swap is a bit wordy. I believe these two
code sequences are equivalent. I'm assuming 0= UNTIL or WHILE is
evaluating the value left by the call to EXECUTE. Does the inner loop
exit when reaching the end of the list? I assume the list ends with an
XT that calls a word which simply returns a TRUE? That seems fairly
expedient.
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?
--
Rick
[toc] | [prev] | [next] | [standalone]
| From | "Rod Pemberton" <dont_use_email@xnothavet.cqm> |
|---|---|
| Date | 2014-06-13 04:16 -0400 |
| Message-ID | <op.xhdvw1ao6zenlw@localhost> |
| In reply to | #31471 |
On Fri, 13 Jun 2014 01:02:40 -0400, rickman <gnuarm@gmail.com> wrote: > On 6/12/2014 10:50 PM, 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 ; > > : run-list ( a -- ) \ address of a structure with an op-sequence > BEGIN DUP @ EXECUTE WHILE CELL+ AGAIN DROP ; > Isn't it time for a RECURSE LEAVE or EXIT ? (untested, probably bad coding style jumping out of an IF ...) DUP @ IF EXECUTE CELL+ RECURSE THEN ; > I'm assuming 0= UNTIL or WHILE is evaluating the value left by the > call to EXECUTE. Does the inner loop exit when reaching the end of > the list? No, he was drunk. He meant to test for FALSE after @ before the EXECUTE. Rod Pemberton
[toc] | [prev] | [next] | [standalone]
| From | rickman <gnuarm@gmail.com> |
|---|---|
| Date | 2014-06-13 05:22 -0400 |
| Message-ID | <lnefs1$tgk$1@dont-email.me> |
| In reply to | #31474 |
On 6/13/2014 4:16 AM, Rod Pemberton wrote: > On Fri, 13 Jun 2014 01:02:40 -0400, rickman <gnuarm@gmail.com> wrote: >> On 6/12/2014 10:50 PM, 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 ; >> >> : run-list ( a -- ) \ address of a structure with an op-sequence >> BEGIN DUP @ EXECUTE WHILE CELL+ AGAIN DROP ; >> > > Isn't it time for a RECURSE LEAVE or EXIT ? > (untested, probably bad coding style jumping out of an IF ...) > > DUP @ IF EXECUTE CELL+ RECURSE THEN ; > >> I'm assuming 0= UNTIL or WHILE is evaluating the value left by the >> call to EXECUTE. Does the inner loop exit when reaching the end of >> the list? > > No, he was drunk. He meant to test for FALSE after @ before the EXECUTE. So you think the list is null terminated? -- Rick
[toc] | [prev] | [next] | [standalone]
| From | "Rod Pemberton" <dont_use_email@xnothavet.cqm> |
|---|---|
| Date | 2014-06-14 00:33 -0400 |
| Message-ID | <op.xhff9tpi6zenlw@localhost> |
| In reply to | #31478 |
On Fri, 13 Jun 2014 05:22:22 -0400, rickman <gnuarm@gmail.com> wrote: > On 6/13/2014 4:16 AM, Rod Pemberton wrote: >> He meant to test for FALSE after @ before the EXECUTE. > > So you think the list is null terminated? > I assumed that was his intent, yes. Otherwise, the design is somewhat ... backwards, don't you think? What if you want to use a normal word like SWAP or DUP as part of the op-sequence? Isn't he is checking for a return code from an EXECUTEd word? So, how do you do that? Are you going to do the following just to use DUP ? ... : DUP DUP TRUE ; Rod Pemberton
[toc] | [prev] | [next] | [standalone]
| From | rickman <gnuarm@gmail.com> |
|---|---|
| Date | 2014-06-14 01:15 -0400 |
| Message-ID | <lnglos$678$1@dont-email.me> |
| In reply to | #31510 |
On 6/14/2014 12:33 AM, Rod Pemberton wrote: > On Fri, 13 Jun 2014 05:22:22 -0400, rickman <gnuarm@gmail.com> wrote: >> On 6/13/2014 4:16 AM, Rod Pemberton wrote: > >>> He meant to test for FALSE after @ before the EXECUTE. >> >> So you think the list is null terminated? >> > > I assumed that was his intent, yes. Otherwise, the design is > somewhat ... backwards, don't you think? What if you want to > use a normal word like SWAP or DUP as part of the op-sequence? > Isn't he is checking for a return code from an EXECUTEd word? > So, how do you do that? Are you going to do the following > just to use DUP ? ... > > : DUP DUP TRUE ; No, I understand the intent now. I'm sure he would not be using DUP in this list. Each word used in his list is a word he wrote to use in the list and so it returns a status which is used to control the loop. If you want to argue whether he should be writing such an app, I'll leave you to it. It's his app and he can define his own needs. -- Rick
[toc] | [prev] | [next] | [standalone]
| From | bruce.mcfarling@gmail.com |
|---|---|
| Date | 2014-06-13 23:45 -0700 |
| Message-ID | <9da78510-24fc-46f8-bcf8-379885fac4d8@googlegroups.com> |
| In reply to | #31510 |
On Saturday, June 14, 2014 12:33:19 AM UTC-4, Rod Pemberton wrote: > On Fri, 13 Jun 2014 05:22:22 -0400, rickman <gnuarm At Google's Mail dcom> wrote: >> On 6/13/2014 4:16 AM, Rod Pemberton wrote: >>> He meant to test for FALSE after @ before the EXECUTE. >> So you think the list is null terminated? > I assumed that was his intent, yes. Otherwise, the design is > somewhat ... backwards, don't you think? What if you want to > use a normal word like SWAP or DUP as part of the > op-sequence? We've already covered those use cases. If you want to do it because you are drunk, stop programming until sober. If you want to do it because you are too tired to think straight, stop programming until better rested. The OP clearly specified a scenario in which four TASKS have to be performed in an endless loop, with each returning a status flag, and each running in order unless one failed, then it restarts at the beginning. I pointed out one way to do it is with a state machine. The notion that one of those tasks would be "SWAP" and another "DUP" is quite La La land stuff. As set up, the status return for do not continue is 0 and for continue is anything non-zero. If error is more varied than success (as is often the case), then that could well be flipped, with 0 as success and some non-zero error code on failure. CREATE op-sequence ' op-a , ' op-b , ' op-c , ' op-d , ' TRUE , : run-sequence ( a -- ) \ addr of an op sequence structure BEGIN DUP @ EXECUTE 0= WHILE CELL+ UNTIL DROP ; : run-machine ( a -- ) \ addr of an op-sequence structure >R BEGIN R@ run-sequence AGAIN ; op-sequence run-machine A second way is to spread the state machine among the operations, with each operation built on a patten of (assuming at this point that 0=success, non-zero=error, restart): \ op-a ( fl1 -- fl2 ) : op-a ( fl1 -- fl2 ) \ Only proceed if fl1=0, return 0 on success 0= IF FALSE EXIT THEN \ ... continue ... Then its: : op-sequence ( -- return ) \ ops automatically fall through on failure 0 op-a op-b op-c op-d ; : run-machine ( -- ) BEGIN op-sequence drop AGAIN ;
[toc] | [prev] | [next] | [standalone]
| From | bruce.mcfarling@gmail.com |
|---|---|
| Date | 2014-06-14 00:00 -0700 |
| Message-ID | <5edd8f5c-4626-4c64-aee2-fccf109b9eaa@googlegroups.com> |
| In reply to | #31521 |
Of course,
: run-sequence ( a -- ) \ addr of an op sequence structure
BEGIN DUP @ EXECUTE 0= WHILE CELL+ REPEAT DROP ;
... since, as the estimable Ms. Rather correctly infers, I've got gforth installed on the basement machine and I not going to run down two stories to test this code right now.
~~~~~~~~~~~~~
Debugging of what is going on is improved if each run returns the final result (0 success allows each process to have distinct failure returns, TRUE is the return for sequence success). With a TRUE xt terminated op-sequence structure:
: run-sequence ( a -- status ) \ addr of an op sequence structure
BEGIN
DUP @ EXECUTE DUP >R 0= WHILE
CELL+ RDROP
REPEAT DROP R> ;
: run-machine ( a -- ) >R BEGIN R@ run-sequence DROP AGAIN ;
[toc] | [prev] | [next] | [standalone]
| From | rickman <gnuarm@gmail.com> |
|---|---|
| Date | 2014-06-13 05:26 -0400 |
| Message-ID | <lneg4s$vs0$1@dont-email.me> |
| In reply to | #31474 |
On 6/13/2014 4:16 AM, Rod Pemberton wrote: > On Fri, 13 Jun 2014 01:02:40 -0400, rickman <gnuarm@gmail.com> wrote: >> On 6/12/2014 10:50 PM, 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 ; >> >> : run-list ( a -- ) \ address of a structure with an op-sequence >> BEGIN DUP @ EXECUTE WHILE CELL+ AGAIN DROP ; >> > > Isn't it time for a RECURSE LEAVE or EXIT ? > (untested, probably bad coding style jumping out of an IF ...) > > DUP @ IF EXECUTE CELL+ RECURSE THEN ; BTW, isn't this going to execute the pointer into the list rather than the address in the list, also the IF consumes the XT and the EXECUTE consumes the address so the first time through the routine you get a stack underflow. Perhaps you meant DUP @ DUP IF ... -- Rick
[toc] | [prev] | [next] | [standalone]
| From | "Rod Pemberton" <dont_use_email@xnothavet.cqm> |
|---|---|
| Date | 2014-06-14 00:32 -0400 |
| Message-ID | <op.xhff8w2o6zenlw@localhost> |
| In reply to | #31479 |
On Fri, 13 Jun 2014 05:26:55 -0400, rickman <gnuarm@gmail.com> wrote: > BTW, isn't this going to execute the pointer into the list rather than > the address in the list, also the IF consumes the XT and the EXECUTE > consumes the address so the first time through the routine you get a > stack underflow. > > Perhaps you meant DUP @ DUP IF ... > Perhaps. I said it was untested. I was sleepy too. RP
[toc] | [prev] | [next] | [standalone]
Page 3 of 5 — ← Prev page 1 2 [3] 4 5 Next page →
Back to top | Article view | comp.lang.forth
csiph-web