Perl: the Markov chain saw | |
PerlMonks |
Re^3: strong typingby herveus (Prior) |
on Dec 15, 2004 at 12:39 UTC ( [id://415000]=note: print w/replies, xml ) | Need Help?? |
Howdy!
If you "coerce" a value, you still have the same value, expressed in different units, if you will. For example, 1 (integer) can be coerced into 1.0 (float) without loss of information. However, when you write $a + @b, the operation being performed is not, in my mind, type coercion. There is an implicit operation being performed on @b, but you cannot say the @b is the same thing as the number of elements it contains. The two values are incommensurable. I am reminded of an advertisement that has been on the air lately that speaks of "miles", "nautical miles" ("a wetter version of miles"), and "square miles" ("a squarier version of miles"), as if they expressed the same thing (before segueing to the point of the advertisement). It's inane to assert that you can somehow compare length with area, just as it does not make sense to think that @z in "$x = $y + @z" can mean "the collection of elements in the array z". Now, the hypothetically legal "@x = $y + @z" could cause @x to contain the elements of @z each with $y added to them, but that's a whole different kettle of fish. Many of the alleged "type coercions" sleepingsquirrel presents are of this sort, where a variable or expression is being evaluated in an unusual context, causing implicit operations to be performed that extract attributes of the variable rather than its value. Perl does this a lot more than most languages. Now, the lengthy dissertation I reply to dodges the fact that many of the examples adduced are obfuscated by the misleading comments appended thereto. Warnings are suppressed at key moments; strictures are misrepresented. It still comes across as trollish...
yours, Michael
In Section
Perl News
|
|