[comp.lang.forth] State smart words in ANS Forth

Mitch.Bradley@ENG.SUN.COM (04/25/91)

> Is there any way to create state-smart words (words that know if they would
> be compiled or interpreted if they were not IMMEDIATE) in dpANS Forth?

Yes.  Same as always:

        : A-STATE-SMART-WORD  ( -- )
           STATE @  IF
              ." I'm compiling a literal" CR
              1234 [COMPILE] LITERAL
           ELSE
              ." Sorry, I have no interpretation behavior" CR
           THEN
        ; IMMEDIATE

Mitch.Bradley@Eng.Sun.COM