|
|
Subscribe / Log in / New account

An interview with Larry Wall (LinuxVoice)

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 8:50 UTC (Fri) by dvdeug (guest, #10998)
In reply to: An interview with Larry Wall (LinuxVoice) by Cyberax
Parent article: An interview with Larry Wall (LinuxVoice)

Perl did not guess their format when it read them in; it read them in as strings. You implicitly told Perl to convert them to numbers when you used a numeric operator on them; if you were concerned that you knew exactly what type they would be converted to, you could have converted them yourself. There are of course heuristics for incompatible types in Python, as I demonstrated by doing a + b with a floating point and b an integer; the only question is how incompatible and in what ways.

If you want to argue that strings should not silently convert to numbers, that's an argument. It seems far away from any discussion of rational numbers in Perl 6.

"use warnings" would tell you if you use "==" on strings. There's shared responsibility when you screw up by using a questionable feature in a language that the system you use has warnings on.


to post comments

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 9:34 UTC (Fri) by rsidd (subscriber, #2582) [Link] (1 responses)

If you want to argue that strings should not silently convert to numbers, that's an argument. It seems far away from any discussion of rational numbers in Perl 6.
Floats should not silently convert to rationals. And apparently this doesn't even require an operation. Merely writing "3.14159" makes perl6 treat it as 314159/100000. It's hard to imagine that this has security implications, though. Just needless complexity and inefficiency.

What happens when interfacing with a C library (say GSL)? Are these "rationals" then converted into floats before calling? And are the return values converted back to "rationals"?

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 19:19 UTC (Fri) by raiph (guest, #89283) [Link]

> Floats should not silently convert to rationals.

I can't imagine any language doing that. If your comment is aimed at Perl (5 or 6) then I think this is another manifestation of overall confusion about decimal fractions.

https://en.wikipedia.org/wiki/Decimal#Decimal_fractions

> Merely writing "3.14159" makes perl6 treat it as 314159/100000.

Just for emphasis: https://en.wikipedia.org/wiki/Decimal#Decimal_fractions

Hopefully you'll spend a few seconds reading this wikipedia link and you'll go "ahhh". :)

> What happens when interfacing with a C library (say GSL)?

One uses explicit typing in the signature (the list of parameters) of the Perl 6 functions that call the C functions. For example:

sub add(int32, int32) returns int32 is native("libcalculator") { * }

means that one must call the `add` function with two native 32 bit ints.

See http://doc.perl6.org/language/nativecall#Passing_and_Retu... for some more details.

> Are these "rationals" then converted into floats before calling?

They can be. It's controlled by explicit types and explicit type coercions in the signature. For example:

sub foo(Num(Rat), Num) ...

would be callable with:

foo(13/17, 26e3)

> And are the return values converted back to "rationals"?

Rakudo does not currently support signature based coercion of the return value; I don't know whether there's a plan to one day support that.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 20:43 UTC (Fri) by raiph (guest, #89283) [Link] (1 responses)

> Perl did not guess their format when it read them in; it read them in as strings.

Perl 6 lets users directly specify input types for command line args:

perl6 -e 'sub MAIN (Int $int, Rat $rat, $string) { .print and "\t".print and .WHAT.say for $int, $rat, $string }' 42 2 Foo

Usage:
-e '...' <int> <rat> <string>

perl6 -e 'sub MAIN (Int $int, Rat $rat, $string) { .say and .WHAT.say for $int, $rat, $string }' 42 2/10 Foo

42
(Int+{orig-string[Str]})
2/10
(Rat+{orig-string[Str]})
Foo
(Str)

Perl 6 displays an automatically generated usage message until you pass arguments that correspond to the specified types.

When you do, it stores the typed values and the original string values so you can use either as appropriate to your needs.

The design docs suggest a similar mechanism is supposed to be applicable to input other than command line args but Rakudo doesn't support that yet afaik.

> You implicitly told Perl to convert them to numbers when you used a numeric operator on them

A nit: I'd say that treating operands of the `+` operator as numbers is explicit, not implicit.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 22:36 UTC (Fri) by raiph (guest, #89283) [Link]

> A nit: I'd say that treating operands of the `+` operator as numbers is explicit, not implicit.

And, if I did, I'd be wrong.

https://en.wikipedia.org/wiki/Type_conversion


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