Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion References to hash elements?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jeff Clites  
View profile  
 More options Jan 6 2004, 4:49 pm
Newsgroups: perl.perl6.internals
From: jcli...@mac.com (Jeff Clites)
Date: Tue, 6 Jan 2004 13:28:17 -0800
Local: Tues, Jan 6 2004 4:28 pm
Subject: Re: References to hash elements?
[ apologies for the duplicate email message from my last post--mail
client problems... ]

On Jan 6, 2004, at 11:50 AM, Simon Cozens wrote:

> Jeff Clites:
>> $a = $hash{bar};

> Here you used the copy constructor before taking the reference. It
> might look
> like an assignment operator, but it isn't. You're better off thinking
> that
> assignment doesn't exist. It's a copy constructor. It makes the PMC
> referred
> to by $a a copy of the PMC in $hash{bar}. Their values may be "equal"
> but
> they're two different PMCs.

But here what I'm copying is the _contents_ of the hash slot--so I'm
copying a PerlString PMC, for instance.

>> $b = \$hash{bar};

> Here you didn't make a copy before taking the reference. No copy, only
> one
> PMC. It all works.

And here I'm not making a copy, but also the thing I'm taking a
reference to is not the same thing I copied above. Here, it's a
reference to a hash slot.

So maybe the way to think about it is:

$a = $hash{bar};
#This finds the hash slot, pulls out its contents, and copies that
contents into $a.

$b = \$hash{bar};
#This finds the hash slot, takes a reference to it, and places that
reference in $b.

So the first case involves copying a string, and the second involves
creating a reference to a hash slot. In particular, if the hash is
initially empty, the first case should end up with undef in $a (so
nothing actually copied, if undef is a singleton), but $b would
(presumably) still contain a real reference (to a hash slot which
doesn't contain anything yet), which would create a hash entry if you
"$$b = 'goo'". And that reference-to-a-hash-slot is probably a separate
special PMC (it needs to keep track of the hash and key, and work even
if the hash is empty).

JEff


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.