Digest #155 2021-05-22
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)?
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 ;