( "<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"<space> -- c ) BL WORD CHAR+ C@ ;


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 2019-05-20 07:37:31

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 2019-05-20 14:53:40

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 2019-05-20 16:54:34

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 2019-05-21 02:36:47

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