An interview with Larry Wall (LinuxVoice)
An interview with Larry Wall (LinuxVoice)
Posted Jul 24, 2015 20:43 UTC (Fri) by raiph (guest, #89283)In reply to: An interview with Larry Wall (LinuxVoice) by dvdeug
Parent article: An interview with Larry Wall (LinuxVoice)
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.
Posted Jul 24, 2015 22:36 UTC (Fri)
by raiph (guest, #89283)
[Link]
And, if I did, I'd be wrong.
An interview with Larry Wall (LinuxVoice)