>>>>> On 2026-11-17, dxf wrote: >>>>> On 16/11/2026 11:57 am, dxf wrote: >>>>> 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. >> : >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 ; > According to pForth (github) it has DIGIT with the same stack effect > as mine. It differs in that it is case-insensitive i.e. 'a' is treated > as 'A'. Based on that, then this should work: > : UNNIBBLE ( c - n ) > ( Convert a hex digit character into a number ) > 16 DIGIT 0= ABORT" character not in the 0-9a-fA-F range" ; ACK, thanks, it does. I'd say it ends up being more complex this way: DIGIT is implemented in pForth itself (see fth/numberio.fth), and is fairly involved at that, but my code is a prototype anyway, so it makes every sense to use what suitable built-in words that might be available. Like I've said, I intend for the code to eventually run on the MCU itself, and I expect an AVR Forth to be closer to, say, Pygmy Forth, than pForth. About the only reason I'm not writing this prototype in Pygmy is that I haven't figured out a good way to send bits of code from Vi(m) to that particular implementation (even with "CTTY AUX" and ">DOS". "INCLUDE CON", perhaps?) Regardless, Pygmy has -DIGIT , which is similar, but with it using BASE , it's far less suitable: p> : -DIGIT ( c - n) $30 - DUP 9 > IF 7 - DUP $A < OR THEN p> DUP BASE @ U< NOT ABORT" ?" ; Another thing to note is that "7" both here and in >DIGIT above is ASCII-specific. I have no plans for supporting, say, EBCDIC, but something like an explicit [ CHAR A CHAR 9 - 1- ] might be helpful should anyone desire to port the code to such an environment.