( "<spaces>name" -- char )

Skip leading space delimiters. Parse name delimited by a space. Put the value of its first character onto the stack.



Typical use: ... CHAR A CONSTANT "A" ...


T{ CHAR X     -> 58 }T
T{ CHAR HELLO -> 48 }T


BerndPaysanavatar of BerndPaysan Non-XCHAR implementationSuggested reference implementation2015-11-27 20:45:54

: CHAR ( "char" -- c ) BL WORD CHAR+ C@ ;

Reply New Version

mcondronavatar of mcondron Behavior when no text foundComment2019-05-19 13:57:46

When no text is found (i.e. CHAR followed by nothing but spaces until the end of the line) should this be an ambiguous condition, or should CHAR place 0 on the stack?

AntonErtlavatar of AntonErtl

I don't see this defined in the standard at all (not even as ambiguous condition). I guess we should fix this in the standard.

I think a system should react to this condition by reporting an error.

BerndPaysanavatar of BerndPaysan

There's not even a suitable standard throw code available.

Gforth's current behavior is to return whatever character is found after the end of the input buffer, which is a classical read outside boundary problem.

AntonErtlavatar of AntonErtl

I have just fixed this in Gforth, which now produces an error. I have used -16 "Attempt to use zero-length string as a name" as throw code, but it does not quite fit.

mcondronavatar of mcondron

Yes, seems like an error to me, too. Thanks.

Reply New Version