I recall the definition of coroutine call:
CO :
Return to the caller, suspending interpretation of the current
definition, such that when the caller exits, this definition is
resumed
HEX: " temparily switch to HEX for the duration of the current
definition."
A typical use of HEX: is as follows
( print BYTE in hex )
: B. HEX: S>D <# # # #> TYPE ;
( print SINGLE in hex )
: 4? 1+ 4 MOD 0= IF &, HOLD THEN ; \ print &, at regular intervals.
: H. HEX: S>D <# 2 CELLS 1- 0 DO # I 4? LOOP # #> TYPE ;
( print DOUBLE in hex )
: DH. HEX: <# 4 CELLS 1- 0 DO # I 4? LOOP # #> TYPE ;
HEX: is an example use of the use of CO (coroutine).
VARIABLE BASE-TEMP
: HEX:
BASE @ BASE-TEMP !
HEX CO
BASE-TEMP @ BASE !
;
This is ugly so you are tempted to do
: HEX:
BASE @ >R
HEX CO
R> BASE !
;
This doesn't work. The return address is in the way,
assuming there is a return address on the stack.
This also makes the code implementation dependant.
(Marcel Hendrix's >S and S> however would work.)
: HEX:
R> BASE @ >R >R
HEX CO
R> BASE !
;
I hate TUCK ( a b -- b a b )
but I like RTUCK
"save the top of the stack under the return address of a high
level word."
: HEX:
BASE @ RTUCK
HEX CO
R> BASE !
;
Groetjes Albert
I recall the definition of coroutine call:
CO :
Return to the caller, suspending interpretation of the current
definition, such that when the caller exits, this definition is
resumed
HEX: " temparily switch to HEX for the duration of the current
definition."
A typical use of HEX: is as follows
( print BYTE in hex )
: B. HEX: S>D <# # # #> TYPE ;
( print SINGLE in hex )
: 4? 1+ 4 MOD 0= IF &, HOLD THEN ; \ print &, at regular intervals.
: H. HEX: S>D <# 2 CELLS 1- 0 DO # I 4? LOOP # #> TYPE ;
( print DOUBLE in hex )
: DH. HEX: <# 4 CELLS 1- 0 DO # I 4? LOOP # #> TYPE ;
HEX: is an example use of the use of CO (coroutine).
VARIABLE BASE-TEMP
: HEX:
BASE @ BASE-TEMP !
HEX CO
BASE-TEMP @ BASE !
;
This is ugly so you are tempted to do
On 18/03/2026 1:31 am, albert@spenarnc.xs4all.nl wrote:
I recall the definition of coroutine call:
CO :
Return to the caller, suspending interpretation of the current
definition, such that when the caller exits, this definition is
resumed
HEX: " temparily switch to HEX for the duration of the current
definition."
A typical use of HEX: is as follows
( print BYTE in hex )
: B. HEX: S>D <# # # #> TYPE ;
( print SINGLE in hex )
: 4? 1+ 4 MOD 0= IF &, HOLD THEN ; \ print &, at regular intervals.
: H. HEX: S>D <# 2 CELLS 1- 0 DO # I 4? LOOP # #> TYPE ;
( print DOUBLE in hex )
: DH. HEX: <# 4 CELLS 1- 0 DO # I 4? LOOP # #> TYPE ;
HEX: is an example use of the use of CO (coroutine).
VARIABLE BASE-TEMP
: HEX:
BASE @ BASE-TEMP !
HEX CO
BASE-TEMP @ BASE !
;
This is ugly so you are tempted to do
go back to regular methods?
: (H.N) ( u +n -- a2 u2 )
base @ >r hex <# 0 tuck ?do #
i 1+ 4 mod 0= if [char] , hold then loop #>
over c@ [char] , = 1 and /string r> base ! ;
: (H.) ( u -- adr len ) [ 2 cells ] literal (h.n) ;
: (HW.) ( u -- adr len ) 4 (h.n) ;
: (HB.) ( u -- adr len ) 2 (h.n) ;
: (HD.) ( ud -- adr len ) (h.) dup >r holds (h.) r> 1+ negate /string ;
-1 (h.) type FFFF,FFFF,FFFF,FFFF ok
-1 (hw.) type FFFF ok
-1 (hb.) type FF ok
-1 -1 (hd.) type FFFF,FFFF,FFFF,FFFF,FFFF,FFFF,FFFF,FFFF ok
In article <69b99106$1@news.ausics.net>, dxf <dxforth@gmail.com> wrote:
On 18/03/2026 1:31 am, albert@spenarnc.xs4all.nl wrote:
I recall the definition of coroutine call:
CO :
Return to the caller, suspending interpretation of the current
definition, such that when the caller exits, this definition is
resumed
HEX: " temparily switch to HEX for the duration of the current
definition."
A typical use of HEX: is as follows
( print BYTE in hex )
: B. HEX: S>D <# # # #> TYPE ;
( print SINGLE in hex )
: 4? 1+ 4 MOD 0= IF &, HOLD THEN ; \ print &, at regular intervals. >>> : H. HEX: S>D <# 2 CELLS 1- 0 DO # I 4? LOOP # #> TYPE ;
( print DOUBLE in hex )
: DH. HEX: <# 4 CELLS 1- 0 DO # I 4? LOOP # #> TYPE ;
HEX: is an example use of the use of CO (coroutine).
VARIABLE BASE-TEMP
: HEX:
BASE @ BASE-TEMP !
HEX CO
BASE-TEMP @ BASE !
;
This is ugly so you are tempted to do
go back to regular methods?
: (H.N) ( u +n -- a2 u2 )
base @ >r hex <# 0 tuck ?do #
i 1+ 4 mod 0= if [char] , hold then loop #>
over c@ [char] , = 1 and /string r> base ! ;
: (H.) ( u -- adr len ) [ 2 cells ] literal (h.n) ;
: (HW.) ( u -- adr len ) 4 (h.n) ;
: (HB.) ( u -- adr len ) 2 (h.n) ;
: (HD.) ( ud -- adr len ) (h.) dup >r holds (h.) r> 1+ negate /string ;
-1 (h.) type FFFF,FFFF,FFFF,FFFF ok
-1 (hw.) type FFFF ok
-1 (hb.) type FF ok
-1 -1 (hd.) type FFFF,FFFF,FFFF,FFFF,FFFF,FFFF,FFFF,FFFF ok
HEX: was the proposal. The other words are illustration.
Exercise for the reader:
give an example where HEX: would be useful for number
input.
A free stack >S S> (mhx) or an extra stack defined for this
purpose (Bezemer) helps to define HEX: without RTUCK.
The ugly solution (using BASE-TEMP) could be adequate.
Re-entrancy is overrated anyway.
Groetjes Albert
On 18/03/2026 10:47 pm, albert@spenarnc.xs4all.nl wrote:
In article <69b99106$1@news.ausics.net>, dxf <dxforth@gmail.com> wrote:
On 18/03/2026 1:31 am, albert@spenarnc.xs4all.nl wrote:
I recall the definition of coroutine call:
CO :
Return to the caller, suspending interpretation of the current
definition, such that when the caller exits, this definition is
resumed
HEX: " temparily switch to HEX for the duration of the current
definition."
A typical use of HEX: is as follows
( print BYTE in hex )
: B. HEX: S>D <# # # #> TYPE ;
( print SINGLE in hex )
: 4? 1+ 4 MOD 0= IF &, HOLD THEN ; \ print &, at regular intervals. >>>> : H. HEX: S>D <# 2 CELLS 1- 0 DO # I 4? LOOP # #> TYPE ;
( print DOUBLE in hex )
: DH. HEX: <# 4 CELLS 1- 0 DO # I 4? LOOP # #> TYPE ;
HEX: is an example use of the use of CO (coroutine).
VARIABLE BASE-TEMP
: HEX:
BASE @ BASE-TEMP !
HEX CO
BASE-TEMP @ BASE !
;
This is ugly so you are tempted to do
go back to regular methods?
: (H.N) ( u +n -- a2 u2 )
base @ >r hex <# 0 tuck ?do #
i 1+ 4 mod 0= if [char] , hold then loop #>
over c@ [char] , = 1 and /string r> base ! ;
: (H.) ( u -- adr len ) [ 2 cells ] literal (h.n) ;
: (HW.) ( u -- adr len ) 4 (h.n) ;
: (HB.) ( u -- adr len ) 2 (h.n) ;
: (HD.) ( ud -- adr len ) (h.) dup >r holds (h.) r> 1+ negate /string ; >>>
-1 (h.) type FFFF,FFFF,FFFF,FFFF ok
-1 (hw.) type FFFF ok
-1 (hb.) type FF ok
-1 -1 (hd.) type FFFF,FFFF,FFFF,FFFF,FFFF,FFFF,FFFF,FFFF ok
HEX: was the proposal. The other words are illustration.
As a proposal what does HEX: fix? The words you use to illustrate
don't appear to offer advantage. Poorly factored hex output words
are not a good use case for HEX: . Do you have any other examples?
On 19/03/2026 11:51 am, dxf wrote:<SNIP>
On 18/03/2026 10:47 pm, albert@spenarnc.xs4all.nl wrote:
In article <69b99106$1@news.ausics.net>, dxf <dxforth@gmail.com> wrote: >>>> On 18/03/2026 1:31 am, albert@spenarnc.xs4all.nl wrote:
I recall the definition of coroutine call:
CO :
Return to the caller, suspending interpretation of the current
definition, such that when the caller exits, this definition is
resumed
HEX: " temparily switch to HEX for the duration of the current
definition."
HEX: was the proposal. The other words are illustration.
A typical use of HEX: is as follows
( print BYTE in hex )
: B. HEX: S>D <# # # #> TYPE ;
As a proposal what does HEX: fix? The words you use to illustrate
don't appear to offer advantage. Poorly factored hex output words
are not a good use case for HEX: . Do you have any other examples?
In article <69b99106$1@news.ausics.net>, dxf <dxforth@gmail.com> wrote:
On 18/03/2026 1:31 am, albert@spenarnc.xs4all.nl wrote:
I recall the definition of coroutine call:
CO :
Return to the caller, suspending interpretation of the current
definition, such that when the caller exits, this definition is
resumed
HEX: " temparily switch to HEX for the duration of the current
definition."
A typical use of HEX: is as follows
( print BYTE in hex )
: B. HEX: S>D <# # # #> TYPE ;
( print SINGLE in hex )
: 4? 1+ 4 MOD 0= IF &, HOLD THEN ; \ print &, at regular intervals. >>> : H. HEX: S>D <# 2 CELLS 1- 0 DO # I 4? LOOP # #> TYPE ;
( print DOUBLE in hex )
: DH. HEX: <# 4 CELLS 1- 0 DO # I 4? LOOP # #> TYPE ;
HEX: is an example use of the use of CO (coroutine).
VARIABLE BASE-TEMP
: HEX:
BASE @ BASE-TEMP !
HEX CO
BASE-TEMP @ BASE !
;
This is ugly so you are tempted to do
go back to regular methods?
: (H.N) ( u +n -- a2 u2 )
base @ >r hex <# 0 tuck ?do #
i 1+ 4 mod 0= if [char] , hold then loop #>
over c@ [char] , = 1 and /string r> base ! ;
: (H.) ( u -- adr len ) [ 2 cells ] literal (h.n) ;
: (HW.) ( u -- adr len ) 4 (h.n) ;
: (HB.) ( u -- adr len ) 2 (h.n) ;
: (HD.) ( ud -- adr len ) (h.) dup >r holds (h.) r> 1+ negate /string ;
-1 (h.) type FFFF,FFFF,FFFF,FFFF ok
-1 (hw.) type FFFF ok
-1 (hb.) type FF ok
-1 -1 (hd.) type FFFF,FFFF,FFFF,FFFF,FFFF,FFFF,FFFF,FFFF ok
HEX: was the proposal. The other words are illustration.
Exercise for the reader:
give an example where HEX: would be useful for number
input.
A free stack >S S> (mhx) or an extra stack defined for this
purpose (Bezemer) helps to define HEX: without RTUCK.
The ugly solution (using BASE-TEMP) could be adequate.
Re-entrancy is overrated anyway.
Groetjes Albert
: HEX:
BASE @ RTUCK
HEX CO
R> BASE !
;
The deeper question: is CO worth the return stack gymnastics?
The alternative -- a VARIABLE like BASE-TEMP -- is ugly but
at least it doesn't care what's on R.
It has to be on a stack so you can nest such words. The RTUCK / CO
trick there was very clever!
It has to be on a stack so you can nest such words. The RTUCK / CO
trick there was very clever!
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,102 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 492328:10:47 |
| Calls: | 14,132 |
| Calls today: | 2 |
| Files: | 186,278 |
| D/L today: |
3,501 files (1,225M bytes) |
| Messages: | 2,501,393 |