>> print "date" if $var.isa(int); >> print "date" if isa $var: int; >> print "date" if $var ~~ int; >> >> Those should all work. IMO the first reads the best. That will also >> work for C<Int>s, as C<Int> is a subclass of C<int> (I think). > > These only determine if $var is of type int or Int. However: > > my $var = 0; > # or my $var = "0"; > # or my int $var = 0; > # or my num $var = 0; > > # all 4 cases should print "is integer" > print "is integer" if int $var == $var; > > This should work as a more generic method to test Integer *value*, > rather than type, which IMHO is more useful (and more commonly wanted).
Well, in general I think it would be good to have some mechanism for determining the type of the data rather than the type of a representation of the contained value. If I have "0", it's possible I might at some point (this having been user input perhaps) have some reason to care whether it was an integer or a string. I know I hate the fact that, in almost every lang I use, adding the strings "014" and "231" requires me to do ' "" + string1 + "" + string2 ' since if I 'string1 + string2' I get integer addition and end up with a single number 245, or '"" + string1 + string2' becomes the string "245". I've come to accept it, and I realize that 'var-typed(string1) + var-typed(string2)' takes more characters, looks uglier, and is generally more annoying in all ways for that problem, but I imagine there might exist cases where the information is useful ... I suppose it could be stored at input time as a ... variable property (?) that the program sets, but once it's read, I'm not sure the information exists in any meeans to produce the information FOR the property, so it would have to be set in the input functions themselves ... Admittedly, the value-type is goin to be more interesting in a large majority of the cases, so it probably SHOULD continue being the default low-effort result ... I had a point. I think I made it in there. --attriel