Define a primitive data type: Difference between revisions

No edit summary
Line 1,167:
 
<lang perl6>subset Prime of Int where -> $n { $n > 1 and so $n %% none 2 .. $n.sqrt }</lang>
 
=={{header|Phix}}==
{{trans|Euphoria}}
In Phix types are special functions that may be used in declaring the allowed values for a variable. A type must have exactly one parameter and should return true (non-zero) or false (zero). Types can also be called just like other functions. The types '''object''', '''sequence''', '''string''', '''atom''' and '''integer''' are predefined.
<lang Phix>type iten(integer i)
return i>=1 and i<=10
end type</lang>
You can then declare variables of the new type just as you would the builtins
<lang Phix>integer i
iten i10</lang>
and typechecking occurs automatically
<lang Phix>i = 11 -- fine
i10 = 11 -- runtime error</lang>
 
=={{header|PicoLisp}}==
7,820

edits