| [reply] |
Indeed, I would say that run-time dispatching upon the base type (HASH/ARRAY/SCALAR/CODE etc.) of a reference is likewise, something of a 'special case'.
That is all you said, am I missing something, you go on to discuss the types of runtime introspection you are more interested in, but never go back to justify why this is a special case. Your prior reasoning that ...
the fact that it is under compiler/interpreter control, rather than programmer control, makes it a somewhat different animal to the normal.
... has several holes in it. First, all code is under the control of the compiler/interpreter, so what makes this a special case. When I say:
my $x = "Foo" . 10;
A conversion happens to the IV that stores the 10 so that it can be concatenated to the string "Foo". You could argue that this conversion is implicit, but really any programmer with even a cursory knowledge of Perl would know that the 10 will get converted to a string before it is concatenated, so is it really that implicit? Or is it really pretty explicit? I would argue for the later. A stricter language, I will use OCaml so that you can compile the example if you like, would look like this:
let x = "Foo" ^ int_as_string(10)
The 10 must first be converted from an integer into a string manually by the programmer, but is this really all that different from the Perl version?
Now, here I would agree with you, Perl could use does use compile time decision making to determine that the literal 10 and the literal "Foo" are going to be concatenated and actually replace this with the string "Foo10" and thereby eliminate the need for any runtime introspection/conversion of the IV. However, this type of thing only works if you only have literal values. Even if we do introduce variables, we still need to know (at compile-time) the type of our variables if we are to have the compiler generate code that doesn't require runtime introspection.
UPDATE
Thanks to ikegami for pointing out that Perl actually does do the compile time decision making when presented with two literals. B::Concise never lies :)
% perl -MO=Concise -e 'my $x = "Foo" . 10;'
6 <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 1 -e:1) v ->3
5 <2> sassign vKS/2 ->6
3 <$> const[PV "Foo10"] s ->4
4 <0> padsv[$x:1,2] sRM*/LVINTRO ->5
-e syntax OK
| [reply] [d/l] [select] |