Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #17115 > unrolled thread
| Started by | Chris Hinsley <chris.hinsley@gmail.com> |
|---|---|
| First post | 2012-11-07 13:42 +0000 |
| Last post | 2012-11-08 20:50 +0000 |
| Articles | 20 on this page of 45 — 8 participants |
Back to article view | Back to comp.lang.forth
Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-07 13:42 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-07 13:51 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-07 13:56 +0000
Re: Genral advise and comments on callback style words anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-11-07 13:55 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-07 15:29 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-07 15:35 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-07 15:32 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-07 15:37 +0000
Re: Genral advise and comments on callback style words anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-11-08 16:31 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 17:02 +0000
Re: Genral advise and comments on callback style words anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-11-08 17:07 +0000
Re: Genral advise and comments on callback style words Mark Wills <forthfreak@gmail.com> - 2012-11-09 01:16 -0800
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-07 15:41 +0000
Re: Genral advise and comments on callback style words anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-11-08 16:39 +0000
Re: Genral advise and comments on callback style words Brad Eckert <hwfwguy@gmail.com> - 2012-11-07 08:07 -0800
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 12:52 +0000
Re: Genral advise and comments on callback style words humptydumpty <ouatubi@gmail.com> - 2012-11-07 13:04 -0800
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 13:04 +0000
Re: Genral advise and comments on callback style words Mark Wills <forthfreak@gmail.com> - 2012-11-08 06:34 -0800
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 14:40 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 13:14 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 13:23 +0000
Re: Genral advise and comments on callback style words Ouatu Bogdan <ouatubi@gmail.com> - 2012-11-08 13:45 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 13:59 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 14:02 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 15:35 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 16:24 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 16:39 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 16:57 +0000
Re: Genral advise and comments on callback style words "Elizabeth D. Rather" <erather@forth.com> - 2012-11-08 07:56 -1000
Re: Genral advise and comments on callback style words Josh Grams <josh@qualdan.com> - 2012-11-08 13:54 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 14:06 +0000
Re: Genral advise and comments on callback style words Josh Grams <josh@qualdan.com> - 2012-11-08 18:04 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 19:36 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 19:38 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 19:42 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 14:11 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 14:31 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 14:51 +0000
Re: Genral advise and comments on callback style words Josh Grams <josh@qualdan.com> - 2012-11-08 18:23 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 19:57 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 20:04 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 20:17 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 20:29 +0000
Re: Genral advise and comments on callback style words Chris Hinsley <chris.hinsley@gmail.com> - 2012-11-08 20:50 +0000
Page 2 of 3 — ← Prev page 1 [2] 3 Next page →
| From | Chris Hinsley <chris.hinsley@gmail.com> |
|---|---|
| Date | 2012-11-08 13:14 +0000 |
| Message-ID | <2012110813141528599-chrishinsley@gmailcom> |
| In reply to | #17129 |
On 2012-11-07 21:04:20 +0000, humptydumpty said: > Building backward from EXECUTE and applying desired stack-effects, > I've got: > > : HEAD ( lh -- ln ) ; > : SUCC ( ln -- ln' ) ; > > > \ xt ( u ln lh--R|0 ) > : ENUMERATE ( u xt lh -- R|0 ) > ( u xt lh ) swap >R > ( u lh ) dup HEAD > ( u lh ln ) > BEGIN > ( u lh ln ) dup SUCC dup 0= > ( u lh ln ln' f ) IF RDROP 2drop 2drop 0 EXIT THEN > ( u lh ln ln' ) swap 2over > ( u lh ln' ln u lh ) rot swap R@ > ( u lh ln' u ln lh xt ) EXECUTE dup > ( u lh ln' R f=R ) IF RDROP nip nip nip EXIT THEN > ( u lh ln' R ) drop > ( u lh ln' ) AGAIN > ; ?DUP after the EXECUTE ? Then avoid the drop after the THEN ? But then your looking at a taken branch to an abolute jump ! > ( u lh ln' u ln lh xt ) EXECUTE ?dup > ( u lh ln' R f=R ) IF RDROP nip nip nip EXIT THEN > ( u lh ln' ) AGAIN > ; Chris
[toc] | [prev] | [next] | [standalone]
| From | Chris Hinsley <chris.hinsley@gmail.com> |
|---|---|
| Date | 2012-11-08 13:23 +0000 |
| Message-ID | <2012110813235763416-chrishinsley@gmailcom> |
| In reply to | #17149 |
On 2012-11-08 13:14:15 +0000, Chris Hinsley said: > On 2012-11-07 21:04:20 +0000, humptydumpty said: >> Building backward from EXECUTE and applying desired stack-effects, >> I've got: >> >> : HEAD ( lh -- ln ) ; >> : SUCC ( ln -- ln' ) ; >> >> >> \ xt ( u ln lh--R|0 ) >> : ENUMERATE ( u xt lh -- R|0 ) >> ( u xt lh ) swap >R >> ( u lh ) dup HEAD >> ( u lh ln ) >> BEGIN >> ( u lh ln ) dup SUCC dup 0= >> ( u lh ln ln' f ) IF RDROP 2drop 2drop 0 EXIT THEN >> ( u lh ln ln' ) swap 2over >> ( u lh ln' ln u lh ) rot swap R@ >> ( u lh ln' u ln lh xt ) EXECUTE dup >> ( u lh ln' R f=R ) IF RDROP nip nip nip EXIT THEN >> ( u lh ln' R ) drop >> ( u lh ln' ) AGAIN >> ; > > ?DUP after the EXECUTE ? Then avoid the drop after the THEN ? But then > your looking at a taken branch to an abolute jump ! > >> ( u lh ln' u ln lh xt ) EXECUTE ?dup >> ( u lh ln' R f=R ) IF RDROP nip nip nip EXIT THEN >> ( u lh ln' ) AGAIN >> ; > > Chris So better to do: EXECUTE ?DUP UNTIL RDROP NIP NIP NIP ; Chris
[toc] | [prev] | [next] | [standalone]
| From | Ouatu Bogdan <ouatubi@gmail.com> |
|---|---|
| Date | 2012-11-08 13:45 +0000 |
| Message-ID | <slrnk9ndne.knj.ouatubi@localhost.localdomain> |
| In reply to | #17149 |
On 2012-11-08, Chris Hinsley <chris.hinsley@gmail.com> wrote: > On 2012-11-07 21:04:20 +0000, humptydumpty said: >> Building backward from EXECUTE and applying desired stack-effects, >> I've got: >> >> : HEAD ( lh -- ln ) ; >> : SUCC ( ln -- ln' ) ; >> >> >> \ xt ( u ln lh--R|0 ) >> : ENUMERATE ( u xt lh -- R|0 ) >> ( u xt lh ) swap >R >> ( u lh ) dup HEAD >> ( u lh ln ) >> BEGIN >> ( u lh ln ) dup SUCC dup 0= >> ( u lh ln ln' f ) IF RDROP 2drop 2drop 0 EXIT THEN >> ( u lh ln ln' ) swap 2over >> ( u lh ln' ln u lh ) rot swap R@ >> ( u lh ln' u ln lh xt ) EXECUTE dup >> ( u lh ln' R f=R ) IF RDROP nip nip nip EXIT THEN >> ( u lh ln' R ) drop >> ( u lh ln' ) AGAIN >> ; > > ?DUP after the EXECUTE ? Then avoid the drop after the THEN ? But then > your looking at a taken branch to an abolute jump ! > >> ( u lh ln' u ln lh xt ) EXECUTE ?dup >> ( u lh ln' R f=R ) IF RDROP nip nip nip EXIT THEN >> ( u lh ln' ) AGAIN >> ; > > Chris > Hi! Where dou see word `?dup' used in code I posted? Have a nice day, humptydumpty
[toc] | [prev] | [next] | [standalone]
| From | Chris Hinsley <chris.hinsley@gmail.com> |
|---|---|
| Date | 2012-11-08 13:59 +0000 |
| Message-ID | <2012110813594390418-chrishinsley@gmailcom> |
| In reply to | #17151 |
On 2012-11-08 13:45:27 +0000, Ouatu Bogdan said: > On 2012-11-08, Chris Hinsley <chris.hinsley@gmail.com> wrote: >> On 2012-11-07 21:04:20 +0000, humptydumpty said: >>> Building backward from EXECUTE and applying desired stack-effects, >>> I've got: >>> >>> : HEAD ( lh -- ln ) ; >>> : SUCC ( ln -- ln' ) ; >>> >>> >>> \ xt ( u ln lh--R|0 ) >>> : ENUMERATE ( u xt lh -- R|0 ) >>> ( u xt lh ) swap >R >>> ( u lh ) dup HEAD >>> ( u lh ln ) >>> BEGIN >>> ( u lh ln ) dup SUCC dup 0= >>> ( u lh ln ln' f ) IF RDROP 2drop 2drop 0 EXIT THEN >>> ( u lh ln ln' ) swap 2over >>> ( u lh ln' ln u lh ) rot swap R@ >>> ( u lh ln' u ln lh xt ) EXECUTE dup >>> ( u lh ln' R f=R ) IF RDROP nip nip nip EXIT THEN >>> ( u lh ln' R ) drop >>> ( u lh ln' ) AGAIN >>> ; >> >> ?DUP after the EXECUTE ? Then avoid the drop after the THEN ? But then >> your looking at a taken branch to an abolute jump ! >> >>> ( u lh ln' u ln lh xt ) EXECUTE ?dup >>> ( u lh ln' R f=R ) IF RDROP nip nip nip EXIT THEN >>> ( u lh ln' ) AGAIN >>> ; >> >> Chris >> > Hi! > > Where dou see word `?dup' used in code I posted? > > Have a nice day, > humptydumpty Sorry I copy and edited your code, should have pointed that out ! Chris
[toc] | [prev] | [next] | [standalone]
| From | Chris Hinsley <chris.hinsley@gmail.com> |
|---|---|
| Date | 2012-11-08 14:02 +0000 |
| Message-ID | <2012110814024527964-chrishinsley@gmailcom> |
| In reply to | #17151 |
>> ?DUP after the EXECUTE ? Then avoid the drop after the THEN ? But then >> your looking at a taken branch to an abolute jump ! If I add !?DUP into my x86 primatives, I can do: \ ( u xt lh -- ln | 0) \ xt api is ( u ln lh -- ln | 0 ) : LISTHEAD-ENUMERATE-FORWARDS DUP DUP LISTHEAD-GET-HEAD BEGIN NIP DUP LISTNODE-GET-SUCC !?DUP WHILE 4 PICK 2 PICK 4 PICK 6 PICK EXECUTE ?DUP UNTIL THEN 2NIP 2NIP NIP ; Which I think is nicer ? I'm still not convinced about not useing PICK ! It avoids doing rot and swaps to just marshal paramaters, and using the return stack rather than 6 PICK is not faster. Chris
[toc] | [prev] | [next] | [standalone]
| From | Chris Hinsley <chris.hinsley@gmail.com> |
|---|---|
| Date | 2012-11-08 15:35 +0000 |
| Message-ID | <2012110815354666733-chrishinsley@gmailcom> |
| In reply to | #17154 |
On 2012-11-08 14:02:45 +0000, Chris Hinsley said: >>> >>> ?DUP after the EXECUTE ? Then avoid the drop after the THEN ? But then >>> your looking at a taken branch to an abolute jump ! > > If I add !?DUP into my x86 primatives, I can do: > > \ ( u xt lh -- ln | 0) > \ xt api is ( u ln lh -- ln | 0 ) > : LISTHEAD-ENUMERATE-FORWARDS > DUP DUP LISTHEAD-GET-HEAD > BEGIN > NIP DUP LISTNODE-GET-SUCC !?DUP > WHILE > 4 PICK 2 PICK 4 PICK > 6 PICK EXECUTE ?DUP > UNTIL THEN > 2NIP 2NIP NIP > ; Oops, missed a DUP ! This is what I have now. \ ( u xt lh -- r | 0) \ xt api is ( u ln lh -- r | 0 ) : LISTHEAD-ENUMERATE-FORWARDS 2DUP LISTHEAD-GET-HEAD BEGIN NIP DUP LISTNODE-GET-SUCC DUP !?DUP WHILE 4 PICK 2 PICK 4 PICK 6 PICK EXECUTE ?DUP UNTIL THEN 2NIP 2NIP NIP ; Chris
[toc] | [prev] | [next] | [standalone]
| From | Chris Hinsley <chris.hinsley@gmail.com> |
|---|---|
| Date | 2012-11-08 16:24 +0000 |
| Message-ID | <2012110816241243818-chrishinsley@gmailcom> |
| In reply to | #17164 |
On 2012-11-08 15:35:46 +0000, Chris Hinsley said: > \ ( u xt lh -- r | 0) > \ xt api is ( u ln lh -- r | 0 ) > : LISTHEAD-ENUMERATE-FORWARDS > 2DUP LISTHEAD-GET-HEAD > BEGIN > NIP DUP LISTNODE-GET-SUCC > DUP !?DUP > WHILE > 4 PICK 2 PICK 4 PICK > 6 PICK EXECUTE ?DUP > UNTIL THEN > 2NIP 2NIP NIP > ; > > Chris Ok, how about this one ! Yes I know it uses PICK but it's got a nice feel to it ! \ ( u xt lh -- r | 0 ) \ xt api is ( u ln lh -- r | 0 ) : LISTHEAD-ENUMERATE-FORWARDS DUP LISTHEAD-GET-HEAD BEGIN DUP LISTNODE-GET-SUCC DUP WHILE 4 PICK ROT 3 PICK 5 PICK EXECUTE ?DUP UNTIL THEN 2NIP 2NIP ; Chris
[toc] | [prev] | [next] | [standalone]
| From | Chris Hinsley <chris.hinsley@gmail.com> |
|---|---|
| Date | 2012-11-08 16:39 +0000 |
| Message-ID | <2012110816390087074-chrishinsley@gmailcom> |
| In reply to | #17165 |
On 2012-11-08 16:24:12 +0000, Chris Hinsley said: > \ ( u xt lh -- r | 0 ) > \ xt api is ( u ln lh -- r | 0 ) > : LISTHEAD-ENUMERATE-FORWARDS > DUP LISTHEAD-GET-HEAD > BEGIN > DUP LISTNODE-GET-SUCC DUP > WHILE > 4 PICK ROT 3 PICK > 5 PICK EXECUTE ?DUP > UNTIL THEN > 2NIP 2NIP > ; > > Chris What that turns into after my >FIELD words does its magic is: \ ( u xt lh -- r | 0 ) \ xt api is ( u ln lh -- r | 0 ) : LISTHEAD-ENUMERATE-FORWARDS DUP ! BEGIN DUP ! DUP WHILE 4 PICK ROT 3 PICK 5 PICK EXECUTE ?DUP UNTIL THEN 2NIP 2NIP ; And there's a possible arguement now for: \ ( u xt lh -- r | 0 ) \ xt api is ( u ln lh -- r | 0 ) : LISTHEAD-ENUMERATE-FORWARDS 2DUP SWAP 2>R DUP ! BEGIN DUP ! DUP WHILE 4 PICK ROT 2R@ EXECUTE ?DUP UNTIL THEN 2NIP 2NIP 2RDROP ; Chris
[toc] | [prev] | [next] | [standalone]
| From | Chris Hinsley <chris.hinsley@gmail.com> |
|---|---|
| Date | 2012-11-08 16:57 +0000 |
| Message-ID | <2012110816570850200-chrishinsley@gmailcom> |
| In reply to | #17167 |
On 2012-11-08 16:39:00 +0000, Chris Hinsley said: > > And there's a possible arguement now for: > > \ ( u xt lh -- r | 0 ) > \ xt api is ( u ln lh -- r | 0 ) > : LISTHEAD-ENUMERATE-FORWARDS > 2DUP SWAP 2>R > DUP ! > BEGIN > DUP ! DUP > WHILE > 4 PICK ROT 2R@ EXECUTE ?DUP > UNTIL THEN > 2NIP 2NIP 2RDROP > ; > > Chris I think I'll settle on this, only a single 2 PICK now ! \ ( u xt lh -- r | 0 ) \ xt api is ( u ln lh -- r | 0 ) : LISTHEAD-ENUMERATE-FORWARDS DUP ROT 2>R LISTHEAD-GET-HEAD BEGIN DUP LISTNODE-GET-SUCC DUP WHILE 2 PICK ROT 2R@ EXECUTE ?DUP UNTIL THEN 2RDROP 2NIP ; Chris
[toc] | [prev] | [next] | [standalone]
| From | "Elizabeth D. Rather" <erather@forth.com> |
|---|---|
| Date | 2012-11-08 07:56 -1000 |
| Message-ID | <J6WdnXm3Zo3cbwbNnZ2dnUVZ_uqdnZ2d@supernews.com> |
| In reply to | #17169 |
On 11/8/12 6:57 AM, Chris Hinsley wrote: > On 2012-11-08 16:39:00 +0000, Chris Hinsley said: >> >> And there's a possible arguement now for: >> >> \ ( u xt lh -- r | 0 ) >> \ xt api is ( u ln lh -- r | 0 ) >> : LISTHEAD-ENUMERATE-FORWARDS >> 2DUP SWAP 2>R >> DUP ! >> BEGIN >> DUP ! DUP >> WHILE >> 4 PICK ROT 2R@ EXECUTE ?DUP >> UNTIL THEN >> 2NIP 2NIP 2RDROP >> ; >> >> Chris > > I think I'll settle on this, only a single 2 PICK now ! > > \ ( u xt lh -- r | 0 ) > \ xt api is ( u ln lh -- r | 0 ) > : LISTHEAD-ENUMERATE-FORWARDS > DUP ROT 2>R LISTHEAD-GET-HEAD > BEGIN > DUP LISTNODE-GET-SUCC DUP > WHILE > 2 PICK ROT 2R@ EXECUTE ?DUP > UNTIL THEN > 2RDROP 2NIP > ; Although I generally avoid locals, callbacks and OS calls with many parameters are one example of situations in which they are useful, by letting you provide meaningful names for the parameters and avoiding a lot of stack noise. 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]
| From | Josh Grams <josh@qualdan.com> |
|---|---|
| Date | 2012-11-08 13:54 +0000 |
| Message-ID | <509bb9a2$0$6999$882e7ee2@usenet-news.net> |
| In reply to | #17115 |
Chris Hinsley wrote: <2012110713421835115-chrishinsley@gmailcom> > Folks I have implamented an Amiga style double linked list words set a > few days back and I have an emueration word as follows: > > \ ( u xt lh -- ln | 0) > \ xt api is ( u ln lh -- ln | 0 ) >: LISTHEAD-ENUMERATE-FORWARDS > 0 >R > DUP LISTHEAD-GET-HEAD DUP > BEGIN > NIP DUP LISTNODE-GET-SUCC > DUP > WHILE > 4 PICK 2 PICK 4 PICK > 6 PICK EXECUTE DUP R! > UNTIL THEN > 2DROP 2DROP DROP > R> > ; There are other interfaces that might work better, but sticking to yours, how about: : LISTHEAD-ENUMERATE-FORWARDS ( u xt lh -- ln | 0 ) TUCK SWAP 2>R LISTHEAD-GET-HEAD BEGIN 2DUP LISTNODE-GET-SUCC DUP WHILE 2R@ EXECUTE ?DUP UNTIL ELSE NIP THEN NIP NIP 2R> 2DROP ; And just out of curiosity, why are you calling GET-HEAD and then GET-SUCC before you do anything? Doesn't that skip the first list node? --Josh
[toc] | [prev] | [next] | [standalone]
| From | Chris Hinsley <chris.hinsley@gmail.com> |
|---|---|
| Date | 2012-11-08 14:06 +0000 |
| Message-ID | <201211081406178276-chrishinsley@gmailcom> |
| In reply to | #17152 |
On 2012-11-08 13:54:42 +0000, Josh Grams said: > Chris Hinsley wrote: <2012110713421835115-chrishinsley@gmailcom> >> Folks I have implamented an Amiga style double linked list words set a >> few days back and I have an emueration word as follows: >> >> \ ( u xt lh -- ln | 0) >> \ xt api is ( u ln lh -- ln | 0 ) >> : LISTHEAD-ENUMERATE-FORWARDS >> 0 >R >> DUP LISTHEAD-GET-HEAD DUP >> BEGIN >> NIP DUP LISTNODE-GET-SUCC >> DUP >> WHILE >> 4 PICK 2 PICK 4 PICK >> 6 PICK EXECUTE DUP R! >> UNTIL THEN >> 2DROP 2DROP DROP >> R> >> ; > > There are other interfaces that might work better, but sticking to > yours, how about: > > : LISTHEAD-ENUMERATE-FORWARDS ( u xt lh -- ln | 0 ) > TUCK SWAP 2>R > LISTHEAD-GET-HEAD BEGIN > 2DUP LISTNODE-GET-SUCC > DUP WHILE > 2R@ EXECUTE > ?DUP UNTIL ELSE NIP THEN > NIP NIP 2R> 2DROP ; That's quite nice ! > > And just out of curiosity, why are you calling GET-HEAD and then > GET-SUCC before you do anything? Doesn't that skip the first list node? > > --Josh I'm keeping a 'look ahead' pointer to the next node in the list, as the callback is allowed to trash the current node ! For instance it could remove the node and then your left dangling ! Chris
[toc] | [prev] | [next] | [standalone]
| From | Josh Grams <josh@qualdan.com> |
|---|---|
| Date | 2012-11-08 18:04 +0000 |
| Message-ID | <509bf42e$0$11653$882e7ee2@usenet-news.net> |
| In reply to | #17155 |
Chris Hinsley wrote: <201211081406178276-chrishinsley@gmailcom> > On 2012-11-08 13:54:42 +0000, Josh Grams said: >> Chris Hinsley wrote: <2012110713421835115-chrishinsley@gmailcom> >>> Folks I have implamented an Amiga style double linked list words set a >>> few days back and I have an emueration word as follows: >>> >>> \ ( u xt lh -- ln | 0) >>> \ xt api is ( u ln lh -- ln | 0 ) >>> : LISTHEAD-ENUMERATE-FORWARDS >>> 0 >R >>> DUP LISTHEAD-GET-HEAD DUP >>> BEGIN >>> NIP DUP LISTNODE-GET-SUCC >>> DUP >>> WHILE >>> 4 PICK 2 PICK 4 PICK >>> 6 PICK EXECUTE DUP R! >>> UNTIL THEN >>> 2DROP 2DROP DROP >>> R> >>> ; >> >> And just out of curiosity, why are you calling GET-HEAD and then >> GET-SUCC before you do anything? Doesn't that skip the first list node? > > I'm keeping a 'look ahead' pointer to the next node in the list, as the > callback is allowed to trash the current node ! For instance it could > remove the node and then your left dangling ! Ah, I see. I thought you were keeping the previous one and getting the successor of that after the XT returned. Guess I didn't untangle the PICKs carefully enough. Hrm...I still think it's wrong...unless LISTNODE-GET-SUCC does something really strange like ( node node -- node.next node ), then your WHILE is checking the successor to see if it's null, so you won't process the final element in the list...? Or am I missing something again? --Josh
[toc] | [prev] | [next] | [standalone]
| From | Chris Hinsley <chris.hinsley@gmail.com> |
|---|---|
| Date | 2012-11-08 19:36 +0000 |
| Message-ID | <2012110819364156347-chrishinsley@gmailcom> |
| In reply to | #17174 |
On 2012-11-08 18:04:30 +0000, Josh Grams said: > Chris Hinsley wrote: <201211081406178276-chrishinsley@gmailcom> >> On 2012-11-08 13:54:42 +0000, Josh Grams said: >>> Chris Hinsley wrote: <2012110713421835115-chrishinsley@gmailcom> >>>> Folks I have implamented an Amiga style double linked list words set a >>>> few days back and I have an emueration word as follows: >>>> >>>> \ ( u xt lh -- ln | 0) >>>> \ xt api is ( u ln lh -- ln | 0 ) >>>> : LISTHEAD-ENUMERATE-FORWARDS >>>> 0 >R >>>> DUP LISTHEAD-GET-HEAD DUP >>>> BEGIN >>>> NIP DUP LISTNODE-GET-SUCC >>>> DUP >>>> WHILE >>>> 4 PICK 2 PICK 4 PICK >>>> 6 PICK EXECUTE DUP R! >>>> UNTIL THEN >>>> 2DROP 2DROP DROP >>>> R> >>>> ; >>> >>> And just out of curiosity, why are you calling GET-HEAD and then >>> GET-SUCC before you do anything? Doesn't that skip the first list node? >> >> I'm keeping a 'look ahead' pointer to the next node in the list, as the >> callback is allowed to trash the current node ! For instance it could >> remove the node and then your left dangling ! > > Ah, I see. I thought you were keeping the previous one and getting the > successor of that after the XT returned. Guess I didn't untangle the > PICKs carefully enough. > > Hrm...I still think it's wrong...unless LISTNODE-GET-SUCC does something > really strange like ( node node -- node.next node ), then your WHILE is > checking the successor to see if it's null, so you won't process the > final element in the list...? Or am I missing something again? > > --Josh An Amiga style list header has 3 fields the middle one allways 0. It represents the SUCC of the final node and the PRED of the first node. Imagine it to be list two partial overlapping list nodes, the PRED of the SUCC overlap and are 0. Chris
[toc] | [prev] | [next] | [standalone]
| From | Chris Hinsley <chris.hinsley@gmail.com> |
|---|---|
| Date | 2012-11-08 19:38 +0000 |
| Message-ID | <201211081938193500-chrishinsley@gmailcom> |
| In reply to | #17174 |
On 2012-11-08 18:04:30 +0000, Josh Grams said: > Chris Hinsley wrote: <201211081406178276-chrishinsley@gmailcom> >> On 2012-11-08 13:54:42 +0000, Josh Grams said: >>> Chris Hinsley wrote: <2012110713421835115-chrishinsley@gmailcom> >>>> Folks I have implamented an Amiga style double linked list words set a >>>> few days back and I have an emueration word as follows: >>>> >>>> \ ( u xt lh -- ln | 0) >>>> \ xt api is ( u ln lh -- ln | 0 ) >>>> : LISTHEAD-ENUMERATE-FORWARDS >>>> 0 >R >>>> DUP LISTHEAD-GET-HEAD DUP >>>> BEGIN >>>> NIP DUP LISTNODE-GET-SUCC >>>> DUP >>>> WHILE >>>> 4 PICK 2 PICK 4 PICK >>>> 6 PICK EXECUTE DUP R! >>>> UNTIL THEN >>>> 2DROP 2DROP DROP >>>> R> >>>> ; >>> >>> And just out of curiosity, why are you calling GET-HEAD and then >>> GET-SUCC before you do anything? Doesn't that skip the first list node? >> >> I'm keeping a 'look ahead' pointer to the next node in the list, as the >> callback is allowed to trash the current node ! For instance it could >> remove the node and then your left dangling ! > > Ah, I see. I thought you were keeping the previous one and getting the > successor of that after the XT returned. Guess I didn't untangle the > PICKs carefully enough. > > Hrm...I still think it's wrong...unless LISTNODE-GET-SUCC does something > really strange like ( node node -- node.next node ), then your WHILE is > checking the successor to see if it's null, so you won't process the > final element in the list...? Or am I missing something again? > > --Josh In this forward enum case both HEAD and SUCC end up being just a ! because HEAD and SUCC are 0. But in the backwards enumeration TAIL and PRED are 8 and 4 respectivly. Chris
[toc] | [prev] | [next] | [standalone]
| From | Chris Hinsley <chris.hinsley@gmail.com> |
|---|---|
| Date | 2012-11-08 19:42 +0000 |
| Message-ID | <2012110819424774822-chrishinsley@gmailcom> |
| In reply to | #17177 |
On 2012-11-08 19:38:19 +0000, Chris Hinsley said: > On 2012-11-08 18:04:30 +0000, Josh Grams said: > >> Chris Hinsley wrote: <201211081406178276-chrishinsley@gmailcom> >>> On 2012-11-08 13:54:42 +0000, Josh Grams said: >>>> Chris Hinsley wrote: <2012110713421835115-chrishinsley@gmailcom> >>>>> Folks I have implamented an Amiga style double linked list words set a >>>>> few days back and I have an emueration word as follows: >>>>> >>>>> \ ( u xt lh -- ln | 0) >>>>> \ xt api is ( u ln lh -- ln | 0 ) >>>>> : LISTHEAD-ENUMERATE-FORWARDS >>>>> 0 >R >>>>> DUP LISTHEAD-GET-HEAD DUP >>>>> BEGIN >>>>> NIP DUP LISTNODE-GET-SUCC >>>>> DUP >>>>> WHILE >>>>> 4 PICK 2 PICK 4 PICK >>>>> 6 PICK EXECUTE DUP R! >>>>> UNTIL THEN >>>>> 2DROP 2DROP DROP >>>>> R> >>>>> ; >>>> >>>> And just out of curiosity, why are you calling GET-HEAD and then >>>> GET-SUCC before you do anything? Doesn't that skip the first list node? >>> >>> I'm keeping a 'look ahead' pointer to the next node in the list, as the >>> callback is allowed to trash the current node ! For instance it could >>> remove the node and then your left dangling ! >> >> Ah, I see. I thought you were keeping the previous one and getting the >> successor of that after the XT returned. Guess I didn't untangle the >> PICKs carefully enough. >> >> Hrm...I still think it's wrong...unless LISTNODE-GET-SUCC does something >> really strange like ( node node -- node.next node ), then your WHILE is >> checking the successor to see if it's null, so you won't process the >> final element in the list...? Or am I missing something again? >> >> --Josh > > In this forward enum case both HEAD and SUCC end up being just a ! > because HEAD and SUCC are 0. But in the backwards enumeration TAIL and > PRED are 8 and 4 respectivly. > > Chris Here are the structure defs: 0 BEGIN-STRUCTURE LISTNODE-STRUCTURE FIELD _SUCC FIELD _PRED END-STRUCTURE 0 BEGIN-STRUCTURE LISTHEAD-STRUCTURE FIELD _HEAD FIELD _END FIELD _TAIL END-STRUCTURE And this is the init words for a list to show how an empty list is set up. \ ( lh -- ) : LISTHEAD-INIT DUP >FIELD _END OVER LISTHEAD-SET-HEAD 0 OVER LISTHEAD-SET-END DUP >FIELD _HEAD SWAP LISTHEAD-SET-TAIL ; Regards Chris
[toc] | [prev] | [next] | [standalone]
| From | Chris Hinsley <chris.hinsley@gmail.com> |
|---|---|
| Date | 2012-11-08 14:11 +0000 |
| Message-ID | <2012110814115169871-chrishinsley@gmailcom> |
| In reply to | #17152 |
On 2012-11-08 13:54:42 +0000, Josh Grams said: > Chris Hinsley wrote: <2012110713421835115-chrishinsley@gmailcom> >> Folks I have implamented an Amiga style double linked list words set a >> few days back and I have an emueration word as follows: >> >> \ ( u xt lh -- ln | 0) >> \ xt api is ( u ln lh -- ln | 0 ) >> : LISTHEAD-ENUMERATE-FORWARDS >> 0 >R >> DUP LISTHEAD-GET-HEAD DUP >> BEGIN >> NIP DUP LISTNODE-GET-SUCC >> DUP >> WHILE >> 4 PICK 2 PICK 4 PICK >> 6 PICK EXECUTE DUP R! >> UNTIL THEN >> 2DROP 2DROP DROP >> R> >> ; > > There are other interfaces that might work better, but sticking to > yours, how about: > > : LISTHEAD-ENUMERATE-FORWARDS ( u xt lh -- ln | 0 ) > TUCK SWAP 2>R > LISTHEAD-GET-HEAD BEGIN > 2DUP LISTNODE-GET-SUCC > DUP WHILE > 2R@ EXECUTE > ?DUP UNTIL ELSE NIP THEN > NIP NIP 2R> 2DROP ; > > And just out of curiosity, why are you calling GET-HEAD and then > GET-SUCC before you do anything? Doesn't that skip the first list node? > > --Josh The GET-SUCC'd node isn't the node passed into the callback ! That's the node for the next iteration. Chris
[toc] | [prev] | [next] | [standalone]
| From | Chris Hinsley <chris.hinsley@gmail.com> |
|---|---|
| Date | 2012-11-08 14:31 +0000 |
| Message-ID | <2012110814312086525-chrishinsley@gmailcom> |
| In reply to | #17156 |
>> : LISTHEAD-ENUMERATE-FORWARDS ( u xt lh -- ln | 0 ) >> TUCK SWAP 2>R >> LISTHEAD-GET-HEAD BEGIN >> 2DUP LISTNODE-GET-SUCC >> DUP WHILE >> 2R@ EXECUTE >> ?DUP UNTIL ELSE NIP THEN >> NIP NIP 2R> 2DROP ; Err, I'm not sure that works ! You are skipping the first node. Isn't the 2DUP also blowing up the stack with an extra copy of the original LH each time ? Chris
[toc] | [prev] | [next] | [standalone]
| From | Chris Hinsley <chris.hinsley@gmail.com> |
|---|---|
| Date | 2012-11-08 14:51 +0000 |
| Message-ID | <2012110814515560672-chrishinsley@gmailcom> |
| In reply to | #17157 |
On 2012-11-08 14:31:20 +0000, Chris Hinsley said: >>> >>> : LISTHEAD-ENUMERATE-FORWARDS ( u xt lh -- ln | 0 ) >>> TUCK SWAP 2>R >>> LISTHEAD-GET-HEAD BEGIN >>> 2DUP LISTNODE-GET-SUCC >>> DUP WHILE >>> 2R@ EXECUTE >>> ?DUP UNTIL ELSE NIP THEN >>> NIP NIP 2R> 2DROP ; > > Err, I'm not sure that works ! You are skipping the first node. Isn't > the 2DUP also blowing up the stack with an extra copy of the original > LH each time ? > > Chris And it's not passing the user value into the callback at all ? Chris
[toc] | [prev] | [next] | [standalone]
| From | Josh Grams <josh@qualdan.com> |
|---|---|
| Date | 2012-11-08 18:23 +0000 |
| Message-ID | <509bf899$0$19587$882e7ee2@usenet-news.net> |
| In reply to | #17160 |
Chris Hinsley wrote: <2012110814515560672-chrishinsley@gmailcom> > On 2012-11-08 14:31:20 +0000, Chris Hinsley said: >>> Josh Grams wrote: >>>> >>>> : LISTHEAD-ENUMERATE-FORWARDS ( u xt lh -- ln | 0 ) >>>> TUCK SWAP 2>R >>>> LISTHEAD-GET-HEAD BEGIN >>>> 2DUP LISTNODE-GET-SUCC >>>> DUP WHILE >>>> 2R@ EXECUTE >>>> ?DUP UNTIL ELSE NIP THEN >>>> NIP NIP 2R> 2DROP ; >> >> Err, I'm not sure that works! You are skipping the first node. Yeah, sorry; I thought that's what your code was doing; see my response to your first reply to mine. >> Isn't the 2DUP also blowing up the stack with an extra copy of the >> original LH each time ? > > And it's not passing the user value into the callback at all ? In this case, EXECUTE is ( u ln lh xt -- ln | 0 ), right? So the 2DUP provides two of those four items, and the 2R@ provides the other two. : LISTHEAD-ENUMERATE-FORWARDS ( u xt lh -- ln | 0 ) TUCK SWAP 2>R LISTHEAD-GET-HEAD BEGIN DUP WHILE ( u ln ) ( R: lh xt ) 2DUP LISTNODE-GET-SUCC 2SWAP 2R@ EXECUTE ?DUP UNTIL THEN ( u ln ln|0 ) NIP NIP 2R> 2DROP ; --Josh
[toc] | [prev] | [next] | [standalone]
Page 2 of 3 — ← Prev page 1 [2] 3 Next page →
Back to top | Article view | comp.lang.forth
csiph-web