Define a primitive data type: Difference between revisions

Content added Content deleted
(Whitespace, VB.NET highlighting might be broken? "End" isn't highlighted.)
(Added Perl 6.)
Line 653: Line 653:
$t = 'xyzzy';
$t = 'xyzzy';
# dies, too small. string is 0 interpreted numerically</lang>
# dies, too small. string is 0 interpreted numerically</lang>
=={{header|Perl 6}}==
{{works with|Rakudo|#22 "Thousand Oaks"}}

<lang perl>subset OneToTen of Int where 1 <= * <= 10;

my OneToTen $n = 5;
$n += 6;</lang>

<code>(1 <= * <= 10)(11)</code> returns a false value, so the second assignment throws an exception. You can use any unary function in place of <code>1 <= * <= 10</code>, so this, for example, is also legal:

<lang perl>subset Prime of Int where { $^n > 1 and $^n !% none 2 .. sqrt $^n }</lang>

=={{header|Python}}==
=={{header|Python}}==
This doesn't really apply as Python names don't have a type, but something can be done:
This doesn't really apply as Python names don't have a type, but something can be done: