Smylers writes: > Luke Palmer writes: > > > After this statement: > > > > $x = '345'; > > > > C<$x> is a number. > > Oh. I'd been assuming that quote marks indicated strings, and that, > while a string containing only digits could obviously be treated as a > number (as in Perl 5), it wouldn't be one without being provoked. > > > I should hope it would be treated as one during multimethod dispatch. > > What about: > > $x = '0345'; > > Is that a number? And if so which of these is the same as? > > $x = 345; > $x = 0345;
Well, since those are the same number, I imagine the, um, first? Don't forget that octal numbers look like 0o345. > What about if the variable contains a line read from user input? As a > programmer I'd expect that to be a string -- and if a user happens to > type only digits then it'd be surprising to find the variable is > considered to be of a different type. Yeah, that's a tough question. I'd want it to be a number if it were only digits, unless I wanted it to be a string. Since numbers and strings are polymorphic with one another, maybe it's wrong to think that we can differentiate. But C<sort> has to know when to use C<< <=> >>. Maybe you're right. In the presence of multimethod dispatch, it might be simpler just to tag something with either a num or str marker (I'm completely neglecting Parrot's implementation for this discussion), and treat it as its tag. That wouldn't change the behavior of adding two strings together, or concatenating two numbers, of course. Luke