6.1.0950 CONSTANT CORE

( x "<spaces>name" -- )

Skip leading space delimiters. Parse name delimited by a space. Create a definition for name with the execution semantics defined below.

name is referred to as a "constant".

name Execution:

( -- x )

Place x on the stack.

See:

Rationale:

Typical use: ... DECIMAL 10 CONSTANT TEN ...

Testing:

T{ 123 CONSTANT X123 -> }T
T{ X123 -> 123 }T

T{ : EQU CONSTANT ; -> }T
T{ X123 EQU Y123 -> }T
T{ Y123 -> 123 }T

ContributeContributions

JimPetersonavatar of JimPeterson [293] Possible Reference ImplementationSuggested reference implementation2023-03-11 02:25:18

Maybe this?:

: constant
  >r : r>
  postpone literal
  postpone ;
;

ruvavatar of ruv

Yes, it's a possible and fully compliant implementation. I use this approach.

Please, include also a correct stack diagram into your definitions. It's also an ask to all contributors of reference implementations.

Reply New Version