Define a primitive data type: Difference between revisions

m
(added Factor)
Line 562:
=={{header|Forth}}==
{{ works with|ANS/ISO Forth|}}
Forth can be thought of as a clever Assembler for the Forth two stack virtual machine. As such Standard Forth does not type data but it does implicitly "type" words that act on data in that each function normally operates on a prescribed data type. True to the low level nature of Forth, the responsibility to select the correct action word for specific data is given to the programmer. That being said there are some simple ways to add the requested mechanism to your Forth system.
 
It is worth noting that Forth's penchant for simplicity means we do not need to write new math operators since each operator is atomic and takes arguments from the stack and returns the result to the stack. Therefore we get the desired functionality by only changing the assignment operation. Simplicity has its advantages.
 
=== Method 1: Safe Integer Store operators===
Forth is a fetch and store based virtual machine. If we create a safe versionsversion of store (!) the programmer simply uses this operator rather than the standard store operator.
<LANG>DECIMAL
: CLIP ( n lo hi -- n') ROT MIN MAX ;
Anonymous user