Xiong has asked for the wisdom of the Perl Monks concerning the following question:

Note: If you're unsure what a reference is, better check perlreftut and perlref. This node is not about Perl syntax or internals; it is about the English-ish jargon used to discuss references and related concepts.

Given:

use Devel::Peek; use Perl6::Form; my $dog; my $cat; my $bob; my $sue; { my $pest = 'flea'; $dog = \$pest; $cat = \$pest; $bob = \$dog; $sue = \$cat; } ### say q{}; say 'Dump $dog:'; Dump $dog; say q{}; say 'Dump $cat:'; Dump $cat; say q{}; say 'Dump $bob:'; Dump $bob; say q{}; say 'Dump $sue:'; Dump $sue; say q{}; ### say q{}; say q*| $ $$ $$$ + |*; say q*|-------------------------------------------------------------- +-----|*; print form qq*|dog {<<<<<<<<<<<<<<<} {<<<<<<<<<<<<<<<} + |*, $dog, $$dog, qq*|cat {<<<<<<<<<<<<<<<} {<<<<<<<<<<<<<<<} + |*, $cat, $$cat, qq*|bob {<<<<<<<<<<<<<<<} {<<<<<<<<<<<<<<<} {<<<<<<<<< +<<<} |*, $bob, $$bob, $$$bob, qq*|sue {<<<<<<<<<<<<<<<} {<<<<<<<<<<<<<<<} {<<<<<<<<< +<<<} |*, $sue, $$sue, $$$sue, ; ## end form say q*|-------------------------------------------------------------- +-----|*; say q{}; ### my $t = 'A'; print qq*|$t| *; $t++; say q* $dog eq $cat: *, $dog eq $cat; print qq*|$t| *; $t++; say q* $$dog eq $$cat: *, $$dog eq $$cat; print qq*|$t| *; $t++; say q* $bob eq $sue: *, $bob eq $sue; print qq*|$t| *; $t++; say q* $$bob eq $$sue: *, $$bob eq $$sue; print qq*|$t| *; $t++; say q* $$$bob eq $$$sue: *, $$$bob eq $$$sue; #say $pest; say q{}; __END__ Output: Dump $dog: SV = RV(0xa080f4c) at 0xa080f40 REFCNT = 2 FLAGS = (PADMY,ROK) RV = 0xa216eb8 SV = PV(0x9fbb6d8) at 0xa216eb8 REFCNT = 2 FLAGS = (PADMY,POK,pPOK) PV = 0xa21cff0 "flea"\0 CUR = 4 LEN = 8 Dump $cat: SV = RV(0xa08148c) at 0xa081480 REFCNT = 2 FLAGS = (PADMY,ROK) RV = 0xa216eb8 SV = PV(0x9fbb6d8) at 0xa216eb8 REFCNT = 2 FLAGS = (PADMY,POK,pPOK) PV = 0xa21cff0 "flea"\0 CUR = 4 LEN = 8 Dump $bob: SV = RV(0x9fdd9a4) at 0x9fdd998 REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0xa080f40 SV = RV(0xa080f4c) at 0xa080f40 REFCNT = 2 FLAGS = (PADMY,ROK) RV = 0xa216eb8 SV = PV(0x9fbb6d8) at 0xa216eb8 REFCNT = 2 FLAGS = (PADMY,POK,pPOK) PV = 0xa21cff0 "flea"\0 CUR = 4 LEN = 8 Dump $sue: SV = RV(0x9fdd8f4) at 0x9fdd8e8 REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0xa081480 SV = RV(0xa08148c) at 0xa081480 REFCNT = 2 FLAGS = (PADMY,ROK) RV = 0xa216eb8 SV = PV(0x9fbb6d8) at 0xa216eb8 REFCNT = 2 FLAGS = (PADMY,POK,pPOK) PV = 0xa21cff0 "flea"\0 CUR = 4 LEN = 8 | $ $$ $$$ | |-------------------------------------------------------------------| |dog SCALAR(0xa216eb8) flea | |cat SCALAR(0xa216eb8) flea | |bob REF(0xa080f40) SCALAR(0xa216eb8) flea | |sue REF(0xa081480) SCALAR(0xa216eb8) flea | |-------------------------------------------------------------------| |A| $dog eq $cat: 1 |B| $$dog eq $$cat: 1 |C| $bob eq $sue: |D| $$bob eq $$sue: 1 |E| $$$bob eq $$$sue: 1

Uncommenting the line say $pest; raises a compile-time strict exception, of course; that package $pest is not my $pest. I do this only to make clear that I'm not concerned about this in the least. I don't care what is or is not in scope; only what to call stuff when speaking English to you (for some value of 'English').

This is a fill-in-the-blanks question. Please choose words you want to use to talk about the things in the blanks.

Please be kind enough to number your picks according to the numbered blanks. It's okay to use the same word to fill in more than one blank if you consider the relationships expressed equivalent. You don't need to fill in all of the blanks for your reply to be useful. Thank you.

Summary:

  1. holds,
    has the value,
    contains,
    has,
    is,
  2. points to [something] that points to,
    is a reference to a reference to,
  3. reference to a reference,
    pointer to a reference,
    pointer to a pointer,
    indirect reference,
  4. points to a reference to a reference to,
    is a reference to a reference to a reference to,
    refers to a reference to [a reference to],
  5. RV,
    address,
    referent,
  6. referent of the referent,
    indirect referent,
  7. value of the referent,
  8. value of the referent of the referent,
  9. equal,
    both references to [something],
  10. both references to references to [something],
    [both] indirect references to [something],

Replies are listed 'Best First'.
Re: What's Really in a Reference?
by pemungkah (Priest) on Jul 16, 2010 at 23:16 UTC
    Even though it is slightly sloppy usage, I tend to use "points to" as equivalent to "is a reference to". Generally speaking, if you think of a reference as an arrow drawn on a diagram, a variable which holds a reference to another is at the tail and is called a reference to (or a pointer to), and the item that the reference "points at" is at the head and is called the referent. On occasion you'll hear a referent called a "target", but this is less common, and I haven't used that in my point-by-point response.

    1. $pest has the value 'flea'.
      1. alternatively contains, has, or even is - is is very sloppy semantics, but common when dealing with direct values
    2. $dog points to $pest, which points to 'flea'
      1. alternate: points to a reference to 'flea', or (more precisely) is a reference to a reference to 'flea', if we don't know or care about the name of the intermediate variable
    3. $bob is a reference to a reference to $pest.
      1. a pointer to a reference
      2. a pointer to a pointer
    4. $bob points to a reference to a reference to 'flea'
      1. or is a reference to a reference to a reference to'flea' (more strictly correct)
      2. refers to a reference to
    5. $pest is the referent of $dog
    6. 'flea' is the referent of the referent of $dog
    7. $dog is the referent of $bob
    8. $pest is the referent of the referent of $bob
    9. 'flea' is the value of the referent of $dog
    10. 'flea' is the value of the referent of the referent of $bob
    11. $dog and $cat are both references to $pest
      1. or "both point to $pest", with "both" implying identity of the two reference values
    12. $bob and $sue are both references to references to $pest
      1. or "indirect references to $pest".
      2. If they both pointed to the same reference to pest, I'd say either
        1. the phrase I just used in 12.1 - though that does not communicate that their referent is the same reference, and it implies "one or more" intervening references, not "only one"
        2. say they are references to a reference to $pest.
          1. Note the use of "a reference" to indicate that the referent is the same for both variables; implication is that the reference to $pest may or may not be exactly the same one, only that both of the references pointed to are references to $pest.
          2. Alternative they are "both pointers to the same reference to" $pest, making the fact that they both reference the same reference to $pest explicit, with the implication that this was a deliberate choice for them to have the same value.

    It's remarkably difficult to be precise about this! I think I've covered the alternates you're likely to hear at this point, and it's taken quite a number of edits to be precise.