Please ignore this node, which has been superceded by What's Really in a Reference?. This is not a reflection on any replies, only on the original post.
Original content of this node was so badly written that the fumes nearly tore my head off when I read it over in the light of day. It confused and outraged some readers (and rightly so). I apologize for the entire mess, especially for the senile trip down Machine Memory Lane, for which I cannot even figure out my original motivation for inflicting on the Monastery.
Having rewritten the node in what I hope to be an improvement, I shoveled the steaming dungheap into Bit Hell, since NodeReaper was too busy drinking piņa coladas to touch it. However, tye has demanded its return; so, here it is.
Let's define, for demo purposes, an odd little computer with byte-size memory words but only four of them. Since there are only four words, two bits suffice to represent any memory location:
|----DECIMAL --| |------BINARY-------| ADDRESS VALUE ADDRESS VALUE ======= ===== ======= ========= 0 2 00 0000 0010 1 7 01 0000 0111 2 3 10 0000 0011 3 42 11 0010 1010It's clear that address 0 contains the value 2, which is a valid address. Address 1 contains the value 7, which is not. Address 2 contains the value 3, also a valid address; address 3 contains 42.
Since the value 3 in address 2 is itself a valid address, it's meaningful to say, at some level of abstraction, that address 2 contains 42 indirectly. Even address 0 may be said to contain 42 through double indirection.
Right away we run the risk of confusion. If we leave off the English word 'address', then we obtain peculiar statements such as '0 contains 2'. We want a notation such as '$0 contains 2'. The sigil '$' means 'address'. There is no need for a special notation for 2; 2 is 2. That's what is really in that memory location (for some value of 'really'). Nothing is contained in $0 except twoness.
We can abbreviate this to '$0 is 2' at some risk. We have to expand '$...is...' to mean 'address...contains the value...'.
We can then say '$2 is 3'. But then how do we express the relationship between address 0 and the value 3?
Explicitly, we can say '$0 is a pointer to $2 and $2 is 3'. We're advertising the fact that we consider the value 2, stored in $0, to be itself an address. We might shorten this to '$$0 is 3'.
We can continue the process, saying '$$$0 is 42'. No problem.
Now, please don't be mislead into thinking I'm writing Perl here. This is just theoretical notation that happens to coincide.
Perl has a much more complex structure, besides running (you hope) on a machine with more memory. Besides the actual value data shown above, there is also metadata stored. We don't speak of addresses because we don't want to know anything about internal machine state. We do still speak of values.
When we write an expression such as:
$foo = 88;... we are, in some sense, creating a link from 'foo' to 88. It's not considered a symbolic reference; but in some way 'foo' represents the address, pointer, or handle by which we can grab ahold of 88. If we wrote only 'foo' then we would mean some representation of the string 'foo'. These are very different:
$3 = 42; 3 = 42;The first is valid Perl; the second raises an exception. (Let's please ignore the fact that $0, $1, $2, etc. are special.)
Now scalar variables like $foo and $3 are so common that we just call them, well, 'variables'. We say 'The variable $3 contains the value 42' or just '$3 is 42'.
We are able, in some way, to store '3' itself in another variable, say $2. We're not really storing machine addresses, at least not purely, any more than we're storing the pure machine value 42 or 0010 1010. But we understand that, somehow, we can use $$2 instead of $3.
One Perl syntax for this is:
$3 = 42; $2 = \$3;... and the associated jargon is take a reference to $3. To go the other way:
print $$2;... which prints 42. The associated jargon is dereference $2. Well and good.
Now for the hard part. This node exists to ask and answer one question; I need to ask that replies stick to this, since otherwise the noise (and even wise, off-topic enlightenment) will drown out the simple answer. This is a question about jargon|terminology, not in any way about Perl syntax|code. There are many Perlish ways to enreference and dereference; no need to go over them here. This question is all about the jargon and it can be answered correctly with exactly one (for some value of 'one') word.
In Perl, 42 is called the value of the variable $3. Again, $2 is called a reference to the variable $3.
Q: Fill in the blank: 3 is the ________ of $2. Do not choose the word 'value', for it may be confused with 42.
2010-07-15:
This script takes some references and dumps them with Devel::Peek:
my $A ; my $B ; my $C = 42; $A = \$B; $B = \$C; say '$A:'; Dump( $A ); say '$B:'; Dump( $B ); say '$C:'; Dump( $C ); __END__ Output: $A: SV = RV(0x8a060b4) at 0x8a060a8 REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0x8bc9a38 SV = RV(0x8bc9a44) at 0x8bc9a38 REFCNT = 2 FLAGS = (PADMY,ROK) RV = 0x8bc9a48 SV = IV(0x8bc9a44) at 0x8bc9a48 REFCNT = 2 FLAGS = (PADMY,IOK,pIOK) IV = 42 $B: SV = RV(0x8bc9a44) at 0x8bc9a38 REFCNT = 2 FLAGS = (PADMY,ROK) RV = 0x8bc9a48 SV = IV(0x8bc9a44) at 0x8bc9a48 REFCNT = 2 FLAGS = (PADMY,IOK,pIOK) IV = 42 $C: SV = IV(0x8bc9a44) at 0x8bc9a48 REFCNT = 2 FLAGS = (PADMY,IOK,pIOK) IV = 42From this, I think it's clear that somebody is filling in the blank with RV. Certainly, the values shown above for RV are examples of what I want to talk about.
But I'd like to see something clearer; there's usually more than one way to talk about something. 'RV' and even 'reference value' do not seem quite to be clear and unambiguous.
In replies here, I see 'address', 'referent', and 'thingy'.
Back in the Bad Old Days, if memory location B held, as a value, another memory location C (which held some value, perhaps 42), we would say the 'pointer' B held an 'address'. We also spoke of 'indirect addressing'. But I think this is not quite correct and perhaps misleading in Perl.
I like referent; but the word is so similar to 'reference' that it's nearly as risky in quick conversation as 'reference value'.
Note: I'm not trying to discuss reference counts or what happens when various identifiers go out of scope. In the example above, all variables are in scope for the life of the script; then the world burns. In another example, $C might go out of scope while $B still held, indirectly, the value 42. That's all another topic. I just want to know, no matter what else in scope, a good name for RV.
In reply to What's in a Reference? by Xiong
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |