3 ms·
Somebody must have thought "but" was a useful operator at some point. But from this demo I have absolutely no idea what it does.
by nerdponx 9y ago
Somebody must have thought "but" was a useful operator at some point. But from this demo I have absolutely no idea what it does.
- b2gills 9y agoIt mixes in additional features to a given instance my $old = 0; my $val = $old but True; say $old.Bool; # False say $val.Bool; # True say $val.Numeric; # 0 Which can be thought of as short for my $old = 0; my $val = class :: is Int { method Bool (){ True } }.new( $old ) say $old.Bool; # False say $val.Bool; # True say $val.Numeric; # 0 Note that under the hood it is a little more complicated so that it will work on any instance. I think this was added as a generalization which replaces the following in Perl 5. my $val = "0 but true"; say $val ? "True" : "False"; # True say 0+$val; # 0