( "<spaces>name" -- )

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

name Execution:

( i * x -- j * x )

Execute the xt that name is set to execute. An ambiguous condition exists if name has not been set to execute an xt.



: DEFER ( "name" -- )
DOES> ( ... -- ... )
   @ EXECUTE ;


T{ DEFER defer2 ->   }T
T{ ' * ' defer2 DEFER! -> }T
T{   2 3 defer2 -> 6 }T

T{ ' + IS defer2 ->   }T
T{    1 2 defer2 -> 3 }T


enochavatar of enoch DEFER this not :-)Proposal2016-09-02 16:14:36

This contribution has been moved to the proposal section.

AntonErtlavatar of AntonErtl

This reply has been moved to the proposal section.

enochavatar of enoch

This reply has been moved to the proposal section.
Reply New Version

tolichavatar of tolich Defer ImplementationComment2020-06-29 06:48:12

In fact, it's just a possible portable implementation and it's not error-free. Like, when DEFERed word is called when the stack is already full, it may cause stack overflow and hence -3 THROW.

The REAL implementation, of course, is just a JMP instruction for native/subroutine/direct code or something as primitive for other code types. So DEFERed word has not to be CREATEd.

ALSO, it would be nice to define THROW codes for the ambiguties related to DEFER, and use a word THROWing one of these values instead of just ABORTing.

AntonErtlavatar of AntonErtl

Reference implementations are always just possible implementations. Forth-2012 is not an implementation standard. A potential for stack overflow does not rule this implementation out (otherwise pretty much every reference implementation in Forth would be ruled out).

There is the myth that the usual implementation uses a direct jump instruction, with IS changing the target address inside that jump. I have looked at several implementations, and I have yet to see this one.

System implementors are free to define throw codes in the range -4095..-256, including for this purpose. However, many implementations initialize deferred words with noop.

Reply New Version