Define a primitive data type: Difference between revisions
Content added Content deleted
(→{{header|Perl 6}}: don't pretend the closure is the most general form) |
|||
Line 855: | Line 855: | ||
# dies, too small. string is 0 interpreted numerically</lang> |
# dies, too small. string is 0 interpreted numerically</lang> |
||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
{{works with|Rakudo Star|2010-08}} |
|||
<lang perl6>subset OneToTen of Int where |
<lang perl6>subset OneToTen of Int where 1..1 |
||
my OneToTen $n = 5; |
my OneToTen $n = 5; |
||
$n += 6;</lang> |
$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 { $ |
<lang perl6>subset Prime of Int where -> $n { $n > 1 and so $n %% none 2 .. $n.sqrt }</lang> |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |