Digest #155 2021-05-22

Contributions

[203] 2021-05-21 17:58:29 JimPeterson wrote:

referenceImplementation - Possible Reference Implementation

Would this be a sufficient reference implementation?:

: /STRING  DUP >R - SWAP R> CHARS + SWAP ;

Are there no checks for when u2 might go negative (or, really, wraps around, as it's considered unsigned)?

Replies

[r695] 2021-05-21 22:33:11 ruv replies:

referenceImplementation - Possible Reference Implementation

Are there no checks for when u2 might go negative?

Formally, u2 cannot be negative since it's an unsigned number (a number that is interpreted as an unsigned number). See data type symbols and their meaning.

In some use-cases it could be a problem if n > u1, but it's out of the scope of the standard, if a user tries to shoot himself in the foot. OTOH, it could be a correct and expected intermediate result.

Would this be a sufficient reference implementation?

Yes, I think. Other possible variants:

: /string ( c-addr1 u1 n -- c-addr2 u2 ) tuck - >r chars + r> ;
: /string ( c-addr1 u1 n -- c-addr2 u2 ) tuck - -rot chars + swap ;