Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re (tilly) 5: Hash slices ?

by tilly (Archbishop)
on Apr 13, 2001 at 18:43 UTC ( #72346=note: print w/ replies, xml ) Need Help??


in reply to (tye)Re: Hash slices ?
in thread Hash slices ?

There is a significant and important difference between how you are supposed to think about things and what goes on under the hood.

merlyn is absolutely right about what concepts Perl's behaviour is intended to give. You are absolutely right about the implementation. It is both possible and likely that a future implementation will render your observation incorrect. It is much less likely that the concept both merlyn and perldata are trying to convey will be invalidated at a future point.

Therefore I like merlyn's answer and do not consider it, implementation trivia notwithstanding, poppycock.


Comment on Re (tilly) 5: Hash slices ?
(tye)Re3: Hash slices ?
by tye (Cardinal) on Apr 13, 2001 at 18:50 UTC

    *Sigh* It appears that you are mixing threads here. I didn't call "poppycock" any assertion by merlyn about "what concepts Perl's behavior is intended to give". I called "poppycock" his claim that "same as" is a reasonable way of documenting "same as, to the point of returning the same things when used in a scalar context".

    Update: See (tye)Re4: List context or not? for a better argument on this.

            - tye (but my friends call me "Tye")
      Your misjudgement of my intent notwithstanding, I answered in the right thread to the statement that I intended to respond to.

      Now you may wish the documentation to be clearer and more verbose.

      However the documentation is right. Optimizations notwithstanding, those two constructs are supposed to be the same as each other. Within Perl you are not supposed to be able to tell any difference. And when the documentation points to two constructs and says that they are the same, then they darned well better be the same in all contexts! Else the documentation is wrong. Which is why the documentation did not so document the case which is not the same in scalar context!

      As for the reasonableness or not of this interpretation, I can only speak for myself. Perhaps I read unusually closely, but on this item I distinctly remember when I originally encountered that documentation that I understood the phrase "the same as" and correctly figured out how it would behave in scalar context. Indeed you can see that in my tenth post here. Now why do I remember that? Because I remember looking at it and wondering what was different between the two that were not listed as being the same.

      So while you could certainly ask for clearer documentation of that fact, the documentation is supposed to be able to interpreted that closely. And in fact we have at least one real life example of someone who did just that.

      Now read what merlyn wrote, again. He never asserted that it is reasonably documented. He just said that it is documented and derivable from the documentation. Contrary to your assertion, that claim is not "poppycock".

        Actually, there are lots of ways to tell those apart. I've mentioned a few (did you read (tye)Re4: List context or not? that I mentioned in my update above?).

        I'm glad that you could "guess" what would happen in a scalar context. But I thought you said that it is documented? You have quite an interesting definition of "documented" if it includes "guess" in the process.

        You also bring up an important concept in Perl: That the use of a scalar context should prevent an operation from wasting the time and/or space of generating a whole list of values.

        To me

        @days[3,4,5]   # same as ($days[3],$days[4],$days[5])
        implied (but did not document) that these two constructs should be the same to the point of neither one wastefully generating a list when used in a scalar context. And I thought the implementation would be smart enough to not even generate the list of subscripts (much less generate the list of values). To do this, the operations that would generate the list of subscripts need to know that they don't need to do this work.

        So that documentation implied to me that the context in which an array slice is used would be "passed inside" the brackets to the code for the subscripts (just like how the context in which a function is called gets "passed inside" to the code for the return value).

        And for the example given, you can't tell that this isn't what was happening since all of the following return the same value:

        scalar( @days[3,4,5] ) @days[ scalar( 3,4,5 ) ] scalar( ($days[3],$days[4],$days[5]) ) $days[5]

        Unfortunately, that optimization has not been implemented. If it were, then the following would also be true:

        @days[3,4,@a]   # same as ($days[3],$days[4],$days[@a])
        which it (currently) isn't.

        So now I can tell you that I find that your apparent definition of the term "documented" is, frankly, poppycock. The most I'd be willing to admit is that the behavior of an array slice in a scalar context is "hinted at in the documentation", but I consider even that a stretch.

        Which is why the documentation did not so document the case which is not the same in scalar context!

        Well, that is an interesting assertion. I won't believe it unless you can find the author of the section and convince me that they actually recall making that conscious decision.

        My guess was actually that the words "same as" were omitted in that case simply because that would make the comment long enough that it might wrap and ruin the format of the example!

        Perhaps you should post PSI::ESP::Pod to CPAN. q-:

        Finally, if "same as" in comments of example code is supposed to mean "same to the point of returning the same value in a scalar context", then please explain, from the same perldata.pod:

        ($map{'red'}, $map{'blue'}, $map{'green'}) = (0x00f, 0x0f0, 0xf00);
        [...]
        # same as map assignment above %map = ('red',0x00f,'blue',0x0f0,'green',0xf00);
        and why these two don't return the same values when used in a scalar context?

                - tye (but my friends call me "Tye")

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://72346]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2014-10-22 03:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (112 votes), past polls