Smylers wrote:
If a 'number' is read in from a file, standard input, a webpage, a
command-line argument, and possibly even a database then it's likely to
be a string to start with.

I realize there are ways to get round this, for example by declaring the
variable as numeric.  But not having to worry about declaring variable
types is quite Perlish.

And the above subtlety is something I wouldn't like to have to explain
to a beginner ("The program works fine when I hardcode 10 into it, but
not when I provide 10 as input!"); treating 10 and "10" differently with
the same operator seems a little PHPish.

I guess we all agree that "10" ~~ Num. So this is a classical example of
a Str&Num type which should be more specific than Str and Num. Thus a
dispatch should hit a postfix:<-->:(Num Str --> Num Str) and yield the
result the Perl 5 programmer expects. The other string decrement is then
postfix:<-->:(Str where { $_ !~~ Num } --> Str). With set subtraction as
(\) this might also be postfix:<-->:(Str (\) Num --> Str). If the
programmer really wants to decrement "10" to "09" she has to cast that
to Str: ("10" as Str)--. So we have "10".HOW === Str but "10".WHAT ===
Num Str.

Regards, TSa.

"The unavoidable price of reliability is simplicity"
  -- C.A.R. Hoare

Reply via email to