Digest #207 2023-02-12
Contributions
referenceImplementation - Possible Reference Implementation
: THRU 1+ SWAP DO I LOAD LOOP ;
(simple, but it's good to have a reference)
Also, there's this for a possible test case:
\ \ \ \ WARNING! This could corrupt your "mass storage" accessible through BLOCK:
: GT1
1 BLOCK 1024 BLANK
S" 1 2 3" 1 BLOCK SWAP CMOVE
UPDATE
2 BLOCK 1024 BLANK
S" 4 5 6" 2 BLOCK SWAP CMOVE
UPDATE
;
: GT2 1 1 THRU + - ;
T{ GT1 -> }T ( TEST THRU IN INTERP. STATE )
T{ 1 2 THRU -> 1 2 3 4 5 6 }T
T{ GT2 -> -4 }T ( TEST THRU IN EXECUTE STATE )
requestClarification - "... the remainder of the current line."?
While 7.3.3 states "A block is conventionally displayed as 16 lines of 64 characters.", this doesn't really solidly define what "... the remainder of the current line." actually means. Does it mean to imply that \
will skip >IN
to the next multiple of 64, or would CR
characters terminate a line?
Maybe this?:
\ \ \ \ WARNING! This could corrupt your "mass storage" accessible through BLOCK:
: GL1
1 BLOCK 1024 BLANK
S" 1 2 3" 1 BLOCK SWAP CMOVE
UPDATE
;
: GL2 1 LOAD + ;
T{ GL1 -> }T ( TEST LOAD IN INTERP. STATE )
T{ 1 LOAD -> 1 2 3 }T
T{ GL2 -> 1 5 }T ( TEST LOAD IN EXECUTE STATE )
Replies
referenceImplementation - Example implementation for ROLL
Very nice, and seems to work well (I'm stealing it!). Would there be any benefit in omitting the 0=
and swapping the if/then clauses?... one less operation per iteration? (same with PICK
)
referenceImplementation - Example implementation for PICK
I have always thought there could be a companion word to PICK
, like this:
: place ( xu xu-1 ... x1 x0 y u -- y xu-1 ... x1 x0 )
dup if rot >r 1- recurse r> exit then drop nip
;
I think Anton wants "place" to mean something else to do with strings. Maybe this could be called "put"?
referenceImplementation - Example implementation for PICK
I don't use PLACE, and I don't recommend that anybody uses it, but I recognize that there is a widely implemented word with that name that stores a counted string or somesuch.
Ulrich Hoffmann has proposed PLACE for standardization.
@JimPeterson, thank you :)
Would there be any benefit in omitting the 0= and swapping the if/then clauses?... one less operation per iteration?
A good optimizing compiler eliminates dup 0=
and just generates an appropriate branching instruction.
If we do manual optimizing, then yes, it's probably better:
: roll ( x0 i*x u.i -- i*x x0 )
dup if swap >r 1- recurse r> swap exit then drop
;