Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Some Insights from a Traveler Between Languages

by demerphq (Chancellor)
on Apr 24, 2005 at 17:36 UTC ( [id://451006]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Some Insights from a Traveler Between Languages
in thread Some Insights from a Traveler Between Languages

In a language like Perl, it's not clear to me that the distinction between "array" and "array ref" is a useful one.

IMO its a pretty useful distinction. For instance:

my @array; my $arrayref=[] my @copy=@array; my $refcopy=$arrayref;

So now what happens to the thing $arrayref references when when we modify $refcopy->[0]? It changes. What happens to @array when we modify $copy[0]. Nothing.

The point is that you can determine many things about manipulating an object by its sigil. For instance a copy of a ref is cheap, a copy of an array is not. Modifying the contents of a ref will change the results of all things using the same ref. Modifing the contents of an array will only change that array or things that reference it.

Maybe im too close to the trees but I see a big difference between them and good reasons to have both. Sure you can provide all the same effects with only references (provided you have a way to clone/copy an array) but there is a lot to be said for making them visually distinct. I mean personally i find

my @copy = @array;
to be preferable to
my $copy=$array->copy;
the former says loudly that a new thing is being created where the latter could be doing anything.

---
demerphq

Replies are listed 'Best First'.
Re^4: Some Insights from a Traveler Between Languages
by doom (Deacon) on Apr 24, 2005 at 21:18 UTC
    In a language like Perl, it's not clear to me that the distinction between "array" and "array ref" is a useful one.
    IMO its a pretty useful distinction. For instance:
    my @array; my $arrayref=[]
    I should probably let the perl 6 experts talk about this, but as I remember it the distinction is being downplayed somewhat for Perl 6. People need to use references so often that in Perl 6 you're going to tend to get references to things by default, rather than as a special case that you need to ask for.
      as I remember it the distinction is being downplayed somewhat for Perl 6. People need to use references so often that in Perl 6 you're going to tend to get references to things by default, rather than as a special case that you need to ask for.

      There is some truth in what you say, but I'm not sure it really applies in this context. Perl6 will still have the distinction between the reference and the thing being referenced. Yes, the basic shorthand dereferencing notation will dereference as many levels as necessary to get down to the referenced object (though I assume there will be a way to dereference just one level, if that's what you need to do), and yes, some builtins will handle things a bit differently, but the distinction between a reference and the thing that it references is certainly not going away. Perl6 will not be Perl5, but it will still be Perl.


      "In adjectives, with the addition of inflectional endings, a changeable long vowel (Qamets or Tsere) in an open, propretonic syllable will reduce to Vocal Shewa. This type of change occurs when the open, pretonic syllable of the masculine singular adjective becomes propretonic with the addition of inflectional endings."  — Pratico & Van Pelt, BBHG, p68
Re^4: Some Insights from a Traveler Between Languages
by Anonymous Monk on Apr 25, 2005 at 01:37 UTC
    ObDisclaimer: I'm no monk, I'm relatively beginner.

    I can't imagine that "my $copy=$array->copy;" is more ambiguous than "my @copy = @array;". The former is IMHO clearer conceptually, the latter is the more ambigiuous to my beginner brain. If I need to copy, I'll be glad to make it explicit with some more typing. Otherwise knowing everything is a ref "normally" would be just peachy for me.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-19 20:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found