Tom Christiansen wrote:
> 
> Perl already does the sanity check for you: "can't call method
> without package or reference".  What you're saying requires the
> programmer to diddle about, which is never a win.

I'll concede that point, with the counter that it lets you get exactly
what you want. Consider:

   $b = $a[0];

If what's in $a[0] is actually a ref (not a number/string), then you get
undef back. Sort of like:

   $b = ref $a[0] ? undef : $a[0];

But you can get the ref back by saying:

   *b = *a[0];

Whether you view this as a big benefit or big PITA probably depends on
how much you do stuff like this. It also runs counter to polymorphic
objects, which I just submitted an RFC on. Ooops.
 
> >You can already tell hashes and arrays apart, why not references vs.
> >simple scalars?
> 
> I *can* tell them apart: can't you?  If ref...

My point exactly - "if ref". You don't have to do this when getting to
arrays versus hashes (imagine they both use '@' for the purposes of this
example):

   $b = ishash @h ? $h["key"] : $h[0];

Because hashes and arrays are different fundamental types. So why with
scalars vs. references?
 
> Dollar means one thing -- singular.
> At sign means many things -- plural.
> 
> (Percent means an assocation of things -- perhaps genitive/possessive.

Don't try to skip out so easily on this distinction with (by the way
%hashes are also plural) :-)

This is my main sticking point. To me, cognitively, there are *4* (not
3) data types in Perl:

   $scalar     -    simple, singular, like "Nate" or 5
   @array      -    ordered, plural, like "Nate", 5, "Tom"
   %hash       -    indexed, plural, like "Nate" => "Wiger"
   *reference  -    complex, either, like *ref = %hash

The key is that references don't hold "just one thing". They hold one,
or many. To me, having $scalars hold references makes as little sense as
if C's ints held structs. 

References are a level above the other types, because they can point to
*any* of them. Currently, a reference can point to a simple scalar, or a
hash, or an array, or an object, etc. Just look at this sample code:

   @array = qw(Nate Tom);
   $array = \@array;
   print $array[0];     # Nate
   print $array->[0];   # Nate too

This is the logical extension of references looking silly. The
counterargument of "don't do that" I think is a little weak here.

Anyways, I might be making a mountain out of a molehill. I can tell the
above apart. But I still think the syntax is imperfect at best. And then
there's the issue of

   print $$$$$$$$$$$stuff;    # ref or scalar?
   print $**********stuff;    # oh, a scalar!
   print ***********stuff;    # oh, a ref!

I think this shouldn't be skimmed over so quickly. But it might be too
minimal a gain.

> Now you can have a list of singular things, where you don't have
> to get all uptight about whether some of those things are primes,
> others are unicode strings, and still others are socket connections.
> 
> This is clean and simple.

You are correct, and I will concede this. Under this RFC, getting to
individual elements becomes stickier. But I'd rather a little more
discussion ensued, because perhaps others have better ways to deal with
this than what I've proposed. 

-Nate

Reply via email to