On 16/11/2026 9:55 am, Ivan Shmakov wrote:
> ...
> I /think/ that UNNIBBLE in particular can be made simpler,
> but it's not obvious to me how. (Or do I just use some
> built-in word here instead?)
My 'built-in' (kernel) word is >DIGIT and was designed to be 'general
purpose'. It's coded in assembler but here's a high-level version.
It's case-sensitive to handle situations where lowercase would amount
to an error. It returns 'char' in the event of error should one want
to print it.
: END postpone EXIT postpone THEN ; immediate
\ >DIGIT >CHAR
\ Cvt numeric char to digit u according to base. Case sensitive.
\ Defined in kernel
: >DIGIT ( char base -- u true | char false )
over [char] 0 - dup #10 #17 within 0= if dup #16 u>
if 7 - then dup rot u< if nip true end dup then
2drop false ;
\ Convert numeric digit u to ASCII character char
\ Defined in kernel
: >CHAR ( u -- char ) dup 9 > if 7 + then [char] 0 + ;