Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.48 KB | None | 0 0
  1. subset VLAN of Int where { $^n > 0 && $^n < 4096 };
  2.  
  3. sub print-vlan-id ( VLAN:D $vlan ) {
  4.     say "VLAN ID: $vlan";
  5. }
  6.  
  7. sub MAIN () {
  8.  
  9.     print-vlan-id(1); # OK, prints VLAN ID: 1
  10.     print-vlan-id(1337); # OK, prints VLAN ID: 1337
  11.     print-vlan-id(Nil); # BOOM. Type check failed in binding to parameter '$vlan'; expected Int but got Nil (Nil)
  12.     print-vlan-id(9999); # BOOM. Constraint type check failed in binding to parameter '$vlan'; expected VLAN but got Int (9999)
  13.  
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement