Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^11: Is there any difference between prototype % and @ ?

by AnomalousMonk (Canon)
on Feb 23, 2013 at 16:56 UTC ( #1020324=note: print w/replies, xml ) Need Help??

in reply to Re^10: Is there any difference between prototype % and @ ?
in thread Is there any difference between prototype % and @ ?

it's a common idiom to use map to create listified hashes map { $_ => 0 } LIST

A hash is commonly initialized from a list, e.g.
    my %hash = qw(a 1  b 2  c 3);
Does the quoted idiom do anything other than generate another list with which to initialize a hash? Can a hash so initialized be considered in any way distinct from a hash created in any other way; in particular, can it usefully be distinguished as 'listified'?

orthogonality always makes sense!

A hash is commonly initialized from a list as in the example given above, and a hash is seamlessly 'listified' in list context as in a statement like
    print %hash;
    my @array = %hash;
but are lists (and, by extension, arrays) really orthogonal with hashes? Despite certain conceptual similarities, my inclination would be to say no: there are just too many differences:

  • A hash can be assigned to an array and all the information inherent in the hash can be accessed and manipulated using standard array and list operators, but this is rarely anything other than an exercise in masochism;
  • An array can be assigned to a hash, but the information inherent in the array is largely destroyed thereby.

Prototypes are just not mature enough!!!

Amen to that, brother! Or rather, they are just not well-named enough. Had they been better named, people like myself who come from C/C++land and adjacent regions would not know instantly what they are – and be instantly wrong!

Replies are listed 'Best First'.
Re^12: Is there any difference between prototype % and @ ?
by LanX (Chancellor) on Feb 23, 2013 at 18:17 UTC
    simple test, try to chain my and BUKs implementation of hgrep, 2 in a row!

    I'll try to propose a solution for all of this including lazy lists after GPW in March.

    Cheers Rolf

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2016-10-01 09:53 GMT
Find Nodes?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:

    Results (575 votes). Check out past polls.