> What is a list reference? > What is an array? ... > What is a list?
Hi Juerd, There was a thread on this not long ago. I forgot it's name. Apo 2 said: [1,2,3] is syntactic sugar for something like: scalar(list(1,2,3)) ... suggesting that lists could have references taken to them, much like an array. But then again, the "something like" gave some wiggle room there. More recently, it was amended to: scalar(array(1,2,3)) (Still no spaces after the commas, grr) As best as I can find there has been no official announcement. It has been suggested that all hashes, arrays, and objects are essentially references. This is consistent with other languages where two things are true at the same time: 1. Arrays and such are passed by reference 1. You don't have to dereference arrays and such before using them Heh, there's that thread: It's subject was "Re: Arrays, lists, referencing (was Re: Arrays vs. Lists)" Let me quote a message from it. Juerd's original message is quoted below. I think this was the most coherent, least objected to message before the subject line really became a lie: > From: [EMAIL PROTECTED] (Michael Lazzaro) > > On Tuesday, February 11, 2003, at 04:56 PM, Deborah Ariel Pickett > wrote: > > >> 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 {...} > > > > And somehow related to all this . . . > <snip> > > I think some of this is in A2, but not all of it. > > Here are some of the answers from my own notes. These behaviors have > all been confirmed on-list by the design team: > > An @array in list context returns a list of its elements > An @array in scalar context returns a reference to itself (NOTE1) > An @array in numeric (scalar) context returns the number of elements > An @array in string (scalar) context returns a join of its elements > > An $arrayref in list context returns an arrayref (NOTE2) > An $arrayref in scalar context returns an arrayref > An $arrayref in numeric (scalar) context returns ??? (NOTE3) > An $arrayref in string (scalar) context returns ??? > > Note that that's pretty consistent with how it works now. > > (NOTE1): This is the big change. It's what allows us to treat arrays > as objects, and call methods on them like @array.length. I don't think > anyone will argue that's not a good thing. > > (NOTE2): Note that this is a non-change. If we changed it so that an > arrayref flattened itself in array context, you could never have > complex data structures, because [[1,2],[3,4]] would always be the same > as [1,2,3,4]. > > (NOTE3): I have not been able to find explicitly confirmed behaviors > for these two. It has been implied that they return $arrayref.length > and $arrayref.string (or whatever those methods are called). Maybe. > On 0, Juerd <[EMAIL PROTECTED]> wrote: > > Hi, > > I'm lost. I read some Perl 6 related things and think I missed an > important announcement. > > What is a list reference? > > It is as if lists and arrays are the same thing in Perl 6, but other > documents use the words as they are used in Perl 5. > > So I guess my actual questions are: > > What is an array? > > What is a list? > > > Regards, > > Juerd