in reply to (Completely OT) - Hero(i)n programming language on Slashdot
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: (Completely OT) - Hero(i)n programming language on Slashdot
by jdporter (Paladin) on Dec 14, 2004 at 17:26 UTC | |
| [reply] |
by sleepingsquirrel (Chaplain) on Dec 14, 2004 at 23:20 UTC | |
-- All code is 100% tested and functional unless otherwise noted. | [reply] |
|
strong typing
by sleepingsquirrel (Chaplain) on Dec 14, 2004 at 16:58 UTC | |
-- All code is 100% tested and functional unless otherwise noted. | [reply] [d/l] |
by hardburn (Abbot) on Dec 14, 2004 at 17:53 UTC | |
This is exactly the same as array.length() in Java. It's not a type conversion.
Those are both scalars. Not a type conversion.
This one is tricky. What the eval actually gets is certain internal information concerning the hash, which happens to be output as a valid perl expression (a division operation). You've lost all real information about the hash, and therefore is not a type conversion.
My own view on this is that hashes and arrays are both subtypes of lists. So it's not so much a conversion between different types than between different subtypes. There are those that disagree, though.
This simply makes a scalar containing 12 that is placed as the first element of the list, and the list is then assigned to an array. The scalar is still there, so it's not a type conversion. I think I've established a pattern here. None of these are really type conversions. "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni. | [reply] [d/l] [select] |
by gmpassos (Priest) on Dec 14, 2004 at 23:21 UTC | |
Humm, no! To make any arithmetic operation we need to convert the string (that are just a sequence of bytes), into numbers, where we use 4 bytes (32 bits processor) to make the calculation. (this is standart calculation ok!) The wonderful job that Perl does for us, with speed, is to convert automatically all the boolean, integer, floating and string types with a single type, SCALAR.
Graciliano M. P. | [reply] [d/l] |
by hardburn (Abbot) on Dec 15, 2004 at 14:12 UTC | |
by jdporter (Paladin) on Dec 15, 2004 at 15:17 UTC | |
| |
by gmpassos (Priest) on Dec 15, 2004 at 22:52 UTC | |
by herveus (Prior) on Dec 14, 2004 at 18:37 UTC | |
There's a whole bunch of misdirection in them thar comments... use strict; #try to catch as many type errors as possibleWrong... The strict pragma is meant to "restrict unsafe constructs", according to its POD. This is not the same thing as "catching type errors". See below for applications... Misleading... This isn't "type coercion". This is "evaluation in a scalar context". A reference is a species of scalar that numifies to the memory address of its referent. No coercion here. It's still a scalar. Misleading again. This is "evaluation of a hash in a scalar context". I'm not sure what is actually amusing about the result. It's all there in the documentation. They are both collections, so one could group them as the same meta-type, but they have different characteristics that warrant treating them as different types. The assignment is simply "evaluation of a hash in a list context". 'for %c' produces the same situation. As usage goes, it's value is limited. The assignment sets up a list context, in which there is only one item, the "12". I don't see "type coercion" here either. The two 'print' statements are unremarkable demonstrations of evaluating an array in list and scalar contexts. The output of this line lies. \4 produces a different value than does \4->{"what???"}. In the debugger, 'p \4' prints a ref to a scalar; 'x \4' shows that '4' is the referent. The numeric part of the ref is different from that printed by this line, which is, in fact, a scalar reference to an undefined value. What was this supposed to demonstrate? Further fun with perl -MO=Deparse finds that this print is parsed as How interesting... $scalar_list demonstrates the comma operator in action. What are you trying to demonstrate here? What did you intend to demonstrate with %hash_list? Where does "coercion" come into play here? Oh? How do you demonstrate that? I note that you "cleverly" turn warnings off so the casual observer won't see "Odd number of elements in hash assignment" pop up from the assignment, nor "Use of uninitialized value in print" from the print. What do you think is actually stored in %i? Iterate over the keys and dereference them, if you dare. Hint: it won't work. Spectacularly. Further investigation with Deparse show that this is parsed as creating the list context from which it expects to get an even number of items. The same condition applies above at 'my @t=12;' Why turn strict off here? Which facet of strictures were you hoping to sneak by here? Pray explain. Deparse reports a triple dollar sign, not a double. So, to get to the bottom: bad troll; no biscuit.
yours, Michael | [reply] [d/l] [select] |
by sleepingsquirrel (Chaplain) on Dec 15, 2004 at 05:24 UTC | |
Misleading... This isn't "type coercion". This is "evaluation in a scalar context"I'd be interested to know the difference. Here are some quotes and references I've been able to round up... -- All code is 100% tested and functional unless otherwise noted. | [reply] [d/l] [select] |
by herveus (Prior) on Dec 15, 2004 at 12:39 UTC | |
by chromatic (Archbishop) on Dec 14, 2004 at 17:54 UTC | |
Consider the difference between value typing and container typing. Then consider that you've told perl not to check for type violations. Why would you expect it to complain about type system violations? | [reply] |
by sleepingsquirrel (Chaplain) on Dec 14, 2004 at 18:18 UTC | |
Then consider that you've told perl not to check for type violations.Hmm. Honest question: how do you tell perl to turn on type checking? -- All code is 100% tested and functional unless otherwise noted. | [reply] |
by dragonchild (Archbishop) on Dec 14, 2004 at 18:19 UTC | |
by hardburn (Abbot) on Dec 14, 2004 at 20:13 UTC | |
by sleepingsquirrel (Chaplain) on Dec 14, 2004 at 21:39 UTC | |
| |
by ysth (Canon) on Dec 14, 2004 at 22:41 UTC | |
by hardburn (Abbot) on Dec 14, 2004 at 19:10 UTC | |
One other thing: note that even the most strongly typed langauge will let you define a function that takes one type and returns another:
(If you're not familer with OCaml, the above makes a function that takes a list of integers and sums them, returning a single integer. In OCaml, "int list" and "int" are totally seperate types.) Indeed, a language that didn't allow you to do this would be very limited. "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni. | [reply] [d/l] |