|
|
Subscribe / Log in / New account

An interview with Larry Wall (LinuxVoice)

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 8:21 UTC (Fri) by Cyberax (✭ supporter ✭, #52523)
In reply to: An interview with Larry Wall (LinuxVoice) by mchapman
Parent article: An interview with Larry Wall (LinuxVoice)

> You're making a false comparison there. It would be equally predictable in your Perl code had it used string concatenation instead.
Who said that I want concatenation? I simply want a behavior that doesn't depend on the exact details of input (which very well might be malicious).

> I don't see a big difference between what Perl and Python are doing here. In both cases, the programmer has to know what kinds of values they are working with. With Python that's encoded in the value's type; with Perl that's encoded in the value itself.
There's a fundamental difference here - with Perl6's braindead number treatment, $a + $b can mean DIFFERENT things for different numbers.

Really.

> Scalar::Util::looks_like_number.
Which number? Rational, float, integer, bigint?


to post comments

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 11:46 UTC (Fri) by mchapman (subscriber, #66589) [Link]

> Who said that I want concatenation?

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!


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds