FVALUE

( F: r -- ) ( "<spaces>name" -- ) or ( r "<spaces>name" -- )

Skip leading space delimiters. Parse name delimited by a space. Create a definition for name with the execution semantics defined below, with an initial value equal to r.

name is referred to as a "f-value".

name Execution:

( F: -- r ) or ( -- r )

Place r on the floating point stack. The value of r is that given when name was created, until the phrase "r TO name" is executed, causing a new value of r to be assigned to name.

TO name Run-time:

( F: r -- ) or ( r -- )

Assign the value r to name.

See:

Implementation:

The implementation of FVALUE requires detailed knowledge of the host implementation of VALUE and TO.

VARIABLE %var
: TO 1 %var ! ;

: FVALUE ( F: r -- ) ( "<spaces>name" -- )
   CREATE F,
   DOES> %var @ IF F! ELSE F@ THEN
         0 %var ! ;

: VALUE ( x "<spaces>name" -- )
   CREATE ,
   DOES> %var @ IF ! ELSE @ THEN
         0 %var ! ;

Testing:

T{ 0e0 FVALUE Tval -> }T
T{ Tval -> 0e0 R}T
T{ 1e0 TO Tval -> }T
T{ Tval -> 1e0 R}T
: setTval Tval FSWAP TO Tval ;
T{ 2e0 setTval Tval -> 1e0 2e0 RR}T
T{ 5e0 TO Tval -> }T
: [execute] EXECUTE ; IMMEDIATE
T{ ' Tval ] [execute] [ -> 2e0 R}T

ContributeContributions