3 ms·
>A really dynamically-typed language Raku, previously known as Perl6, has this[1]. sub MAIN(Int $a, Int $b where 10 < $a < $b > 20) { say "OK: $a $b"; }
by Banana699 4y ago
>A really dynamically-typed language
Raku, previously known as Perl6, has this[1].
sub MAIN(Int $a, Int $b where 10 < $a < $b > 20) {
say "OK: $a $b";
}
You can also pull out the "Where" clause to ouside the function and make it define a new type.
Raku is a very awesome language in general, for more reasons than one.
[1] https://andrewshitov.com/2020/08/14/the-pearls-of-raku-issue-5-the-where-clause/ https://andrewshitov.com/2020/08/14/the-pearls-of-raku-issue...
- bjourne 4y agoBut does it generalize? $a > 10 is easy but what if you want "where $a and $b are coprime"? Or a subtype of the integers of all prime numbers.
- Banana699 4y agoYes, "$a > 10" isn't special, any boolean expression in its place is perfectly legal. Define coprime(Int a,Int b) -> Bool and request that coprime($a,$b) holds in the Where clause, define prime(Int a) -> Bool and request it holds for both $a, $b. The same machinery that runs "<" or ">" at runtime would just as well run coprime and prime.