Define a primitive data type: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Improved VB.NET (e.g. added missing operators); converted C# to translation of VB.NET; added explanation)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 952:
 
end program BoundedTest</lang>
 
=={{header|Free Pascal}}==
''See [[#Pascal|Pascal]]''
<lang pascal>type
range = 1..10;
var
n: range;
begin
n := 10;
{$rangeChecks on}
n := n + 10; // will yield a run-time error
end;</lang>
The FPC (Free Pascal compiler) by default does ''not generate'' range checks.
Assigning a value out of range is possible.
Only constant expressions, i. e. expressions that can be evaluated entirely during compile-time, are not accepted, if they are out of range.
 
The compiler directive <tt>{$rangeChecks on}</tt> will enable insertion of range checks.
If an out of range assignment is attempted, a run-time error occurs.
 
Note, in <tt>{$mode Delphi}</tt> range checks are only switchable at procedural level, not on a per expression-basis.
 
=={{header|FreeBASIC}}==
Line 999 ⟶ 1,019:
i = 10 j = 3 k = 4 j + 6 = 9 j + k = 7
</pre>
 
=={{header|Free Pascal}}==
''See [[#Pascal|Pascal]]''
<lang pascal>type
range = 1..10;
var
n: range;
begin
n := 10;
{$rangeChecks on}
n := n + 10; // will yield a run-time error
end;</lang>
The FPC (Free Pascal compiler) by default does ''not generate'' range checks.
Assigning a value out of range is possible.
Only constant expressions, i. e. expressions that can be evaluated entirely during compile-time, are not accepted, if they are out of range.
 
The compiler directive <tt>{$rangeChecks on}</tt> will enable insertion of range checks.
If an out of range assignment is attempted, a run-time error occurs.
 
Note, in <tt>{$mode Delphi}</tt> range checks are only switchable at procedural level, not on a per expression-basis.
 
=={{header|Go}}==
Line 1,831:
$t = 'xyzzy';
# dies, too small. string is 0 interpreted numerically</lang>
 
=={{header|Perl 6}}==
 
<lang perl6>subset OneToTen of Int where 1..10;
 
my OneToTen $n = 5;
$n += 6;</lang>
 
Here the result 11 fails to smartmatch against the range <code>1..10</code>, so the second assignment throws an exception. You may use any valid smartmatch predicate within a <code>where</code> clause, so the following one-argument closure is also legal:
 
<lang perl6>subset Prime of Int where -> $n { $n > 1 and so $n %% none 2 .. $n.sqrt }</lang>
 
=={{header|Phix}}==
Line 1,954 ⟶ 1,943:
(define y 18)
</lang>
 
=={{header|Perl 6Raku}}==
(formerly Perl 6)
 
<lang perl6>subset OneToTen of Int where 1..10;
 
my OneToTen $n = 5;
$n += 6;</lang>
 
Here the result 11 fails to smartmatch against the range <code>1..10</code>, so the second assignment throws an exception. You may use any valid smartmatch predicate within a <code>where</code> clause, so the following one-argument closure is also legal:
 
<lang perl6>subset Prime of Int where -> $n { $n > 1 and so $n %% none 2 .. $n.sqrt }</lang>
 
=={{header|Retro}}==
Line 2,291 ⟶ 2,292:
5
value out of bounds
5</pre>
 
=={{header|Ursala}}==
10,333

edits