<< Home | About Forth | About TurboForth | Download | Language Reference | Resources | Tutorials | YouTube >>


DOES> Search:

In Compilation Words in TurboForth Kernal

Word Name: DOES>
Type: Immediate compiling word
Data Stack Signature: --
Return Stack Signature: --
Availability: V1.0  V1.1  V1.2
Description:

Links a run-time action to a word created with CREATE.

Example:

: MALE ( age -- ) CREATE , DOES> ." Is male and is " @ . ." years old." CR ;
: FEMALE ( age -- ) CREATE , DOES> ." Is female and is " @ . ." years old." CR ;

42 MALE TOM
27 FEMALE SALLY

TOM

(TurboForth displays "TOM is male and is 42 years old")

SALLY

(TurboForth displays "SALLY is female and is 27 years old")

Thus TOM is a member of the class MALE, and SALLY is a member of the class FEMALE.
 

 

Comment:

The run-time action of words created via CREATE is to leave the address of their Parameter Field (PFA) on the stack. The PFA is one cell wide and can be used to store any 16-bit value.

DOES> can be used to assign run-time code to words created with CREATE. Multiple words, all created with CREATE can inherit the same run-time code/behaviour via DOES>, allowing simple classes of words to be created.

See Also: CREATE 

<< Home | About Forth | About TurboForth | Download | Language Reference | Resources | Tutorials | YouTube >>