Anonymous user
Define a primitive data type: Difference between revisions
→{{header|Fortran}}
Line 544:
return i >= 1 and i <= 10
end type</lang>
=={{header|Forth}}==
{{ works with|ANS/ISO Forth|}}
Standard Forth does not type data but it does "type" words that act on data. However 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.
=== Method 1: Safe Integer Store operator===
Forth is fetch and store based virtual machine. If we create a safe version of store (!) the programmer simply uses this operator rather than the standard store operator.
<LANG>DECIMAL
: BETWEEN ( n lo hi -- ) 1+ WITHIN ;
: SAFE! ( n addr -- )
OVER 1 10 BETWEEN 0= ABORT" out of range!"
! ;
VARIABLE X
7 X SAFE! ok
X ? 7 ok
99 X SAFE!
:64: out of range!
99 X >>>SAFE!<<<
Backtrace:
$7FAA2B0C throw
$7FAD4698 c(abort")
</LANG>
=={{header|Fortran}}==
|