4 ms·
Define "useful" none of it is something you'd ever write or use for any real world task. Its useful to illustrate some of the corners of the language that could
by Ultimatt 9y ago
Define "useful" none of it is something you'd ever write or use for any real world task. Its useful to illustrate some of the corners of the language that could cause problems if they were ever abused in horrific/wonderful ways.
- nerdponx 9y agoSomebody 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