Advertisement
cwchen

[Perl 6] Boolean coercion operator.

Sep 30th, 2017
648
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.64 KB | None | 0 0
  1. # Falsey.
  2. ?0 == False or die "Wrong state";   # Zero.
  3. ?0.0 == False or die "Wrong state"; # Zero (as float).
  4. ?"" == False or die "Wrong state";  # Empty string.
  5. ?() == False or die "Wrong state";  # Empty list.
  6. ?{} == False or die "Wrong state";  # Empty hash.
  7. ?Nil == False or die "Wrong state"; # Nil
  8. my $v; ?$v == False or die "Wrong state"; # Undefined variable.
  9.  
  10. # Truthy: all non-falsey values.
  11. ?1 or die "Wrong state";
  12. ?1.0 or die "Wrong state";
  13. ?"Hello World" or die "Wrong state";
  14. ?(1, 2, 3) or die "Wrong state";
  15. ?{"one" => "eins", "two" => "zwei", "three" => "drei"} or die "Wrong state";
  16. my $u = 99; ?$u or die "Wrong state";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement