--

On Tue, 11 Feb 2003 12:28:23  
 Luke Palmer wrote:
>> Date: Tue, 11 Feb 2003 10:34:57 -0800
>> From: Michael Lazzaro <[EMAIL PROTECTED]>
>> 
>> On Monday, February 10, 2003, at 05:56  PM, Luke Palmer wrote:
>> > Indeed, this supports the distinction, which I will reiterate:
>> >
>> >     - Arrays are variables.
>> >     - Lists are values.
>> 
>> My hesitation about the 'arrays are variables' part is that Damian 
>> corrected me on a similar thing when I was writing about scalars.  A 
>> variable is more like "a name of a container for a value", e.g. there's 
>> three parts to it:
>> 
>>     - the name      (what it's called in the namespace)
>>     - the container (a specific container implementation)
>>     - the value     (what's inside it)
>> 

Maybe I'm confused about why there is 
confusion. An array is an object (in fact 
all containers are objects, or 
implementations thereoff). We can call 
methods on it, and dispatch functions 
differently based on it's type - which is 
why we can treat lists and arrays 
differently.

A list is not a object - it is a value, 
immutable. It is the data that the array 
object wraps around.


The name @array names arrays which Perl can 
autovivify. The '@' is part of it's name. If 
 Perl sees a name begining with @ is hasn't 
seen before is creates the array object 
automatically. So 

@array = (1,2,3,4);


really means


@array := Array.new (1,2,3,4)


or possibly (treating = as an overloaded 
operator on the type Array)


(@array := Array.new) = (1,2,3,4)


the commas being operators which construct 
the list value.


Or am I confused?

-Erik

>> So I don't know that arrays are variables, so much as arrays are 
>> containers, if we want to get pedantic about it (which I don't, but... 
>> documentation... sigh).
>
>Well, that doesn't assume the definition of the variable includes a
>namespace entry.  So, yes, I suppose container would be better.  The
>thing the namespace entry points to, but not the value.
>
>> Just to clarify... in P6, is this an array reference, or a list 
>> reference?
>> 
>>      [1,2,3]
>>
>> What about this?
>> 
>>       \@array
>> 
>> I'd say both of them are array references, but there's no variable 
>> associated with the first one 
>
>I'd agree.
>
>> -- it's just an anonymous container.  So I'd rewrite the definition
>> to:
>> 
>>    - Lists are an ordered collection of scalar values
>>    - Arrays are containers that store lists
>
>I think that's a pretty good one.
>
>> (Coupled with Uri's explanations, of course... it's the 'container' 
>> part that allows read/write, as opposed to simply read.)  Yes/no?
>
>Yes, from my perspective, the container is the one that knows
>read/write.  Basically, the only you can't modify lists is that they
>have no operations defined that can modify them.  Arrays on the other
>hand, do.
>
>> 
>> > Arrays are things that know about lists.  They know how to get a
>> > particular element out of a list. They know how to *flatten
>> > themselves, interpolating themselves into the surrounding list.  They
>> > know how to map, grep, sort, splice themselves.  They know how to turn
>> > themselves into a scalar.  Lists don't know how to do these things.
>> 
>> But is it OK for a list to be silently promoted to an array when used 
>> as an array?  So that all of the following would work, and not just 50% 
>> of them?
>> 
>>     (1..10).map {...}
>>     [1..10].map {...}
>
>I don't really know here.  I'm not sure whether this should work....
>I think if lists don't have the C<map> method, that shouldn't work.
>
>>     (@a,@b,@c).pop
>>     [@a,@b,@c].pop
>
>Why would you suppose the former to work?  Or do you mean that to mean
>(@a.pop,@b.pop,@c.pop)?  Can lists have methods?
>
>This clear distinction that I once had in my mind is getting blurrier
>and blurrier.  :(
>
>Luke
>


____________________________________________________________
Get 25MB of email storage with Lycos Mail Plus!
Sign up today -- http://www.mail.lycos.com/brandPage.shtml?pageId=plus 

Reply via email to