An interview with Larry Wall (LinuxVoice)
An interview with Larry Wall (LinuxVoice)
Posted Jul 24, 2015 11:46 UTC (Fri) by mchapman (subscriber, #66589)In reply to: An interview with Larry Wall (LinuxVoice) by Cyberax
Parent article: An interview with Larry Wall (LinuxVoice)
Your Python code asked for it. It seems reasonable to expect that if you're comparing two code snippets you wanted them to do roughly the same thing.
> There's a fundamental difference here - with Perl6's braindead number treatment, $a + $b can mean DIFFERENT things for different numbers.
When does it not mean "add them together and produce a result that is the closest representable value to the answer"?
I have only passing familiarity with Perl 6, but I would be totally surprised if this were ever not the case.
But in Perl 5, whether a particular scalar should be treated as a number or a string depends only on the operator or builtin doing the interpretation. The + operator, for instance, interprets whatever you give it as a number.
There are rules as to how this interpretation is done, and those rules are consistently applied. It seems that you think those rules aren't legitimate because they are based on the value, rather than some "type" associated with that value. If that's actually the case, then I'm afraid no explanation is likely to satisfy you. That's simply how Perl works.
> Which number? Rational, float, integer, bigint?
Again, I refer to Perl 5 only.
Scalar::Util::looks_like_number returns a true value iff Perl thinks the scalar "looks like a number". It's really just as simple as that. "Looks like a number" is quite well-defined by Perl. It has nothing to do with "types", because Perl doesn't have types in that sense.
In practice, something that "looks like a number" can be used as if it actually were an integer or a float, assuming Perl actually had such things.
Why does it not matter whether it's an integer or a float? Simple: that only matters when you use the value. The integer-ness or float-ness of the value is not intrinsic to the value itself. If you use it in an operation that demands a float, it will act like a float. If you use it in an operation that demands an integer, it will act like an integer. Same for strings and booleans. The value isn't any of these, but it will happily act like one if you ask it to.
I really hope this explanation makes sense to you, even if you don't happen to like it. I'm out of ways to explain it!