Re: Quick question: (...) vs [...]

2008-08-09 Thread Patrick R. Michaud
On Fri, Aug 08, 2008 at 11:08:51PM -0400, Brandon S. Allbery KF8NH wrote:
>
> On 2008 Aug 8, at 22:53, John M. Dlugosz wrote:
>
>> What is the difference between (1,2,3) and [1,2,3] ?
>
> IIRC one is a list, the other a reference to a list --- which in perl6  
> will be hidden for the most part. so practically speaking the difference 
> is minimal.

More directly, (1,2,3) will interpolate in list context, while
[1,2,3] will not.

say (1, 2, (3, 4, 5)).elems # 5
say (1, 2, [3, 4, 5]).elems # 3

The first example has a List containing five Ints, the second example
has a List containing two Ints and an Array.

It's also useful to consider the difference between:

$x = (3); # $x becomes an Int
$x = [3]; # $x becomes an Array

Pm


Re: Quick question: (...) vs [...]

2008-08-09 Thread Mark J. Reed
On Sat, Aug 9, 2008 at 7:01 AM, Audrey Tang <[EMAIL PROTECTED]> wrote:
> One is a List and one is an Array; you cannot  push into a list, but you can
> into an array.
>
> my @a := (1,2,3);
> my @b := [1,2,3];
>
> @a.push(4); # fails
> @b.push(4); # works

But note that the first push fails because the symbol @a was *bound*
to the list.   After an ordinary assignment

my @a = (1,2,3);

@a is still an array, which just happens to have been initialized from a list.

@a.push(4); # succeeds


-- 
Mark J. Reed <[EMAIL PROTECTED]>


Re: Quick question: (...) vs [...]

2008-08-09 Thread Audrey Tang

John M. Dlugosz 提到:

What is the difference between (1,2,3) and [1,2,3] ?


One is a List and one is an Array; you cannot  push into a list, but you 
can into an array.


my @a := (1,2,3);
my @b := [1,2,3];

@a.push(4); # fails
@b.push(4); # works

Cheers,
Audrey



Re: Quick question: (...) vs [...]

2008-08-08 Thread Brandon S. Allbery KF8NH


On 2008 Aug 8, at 22:53, John M. Dlugosz wrote:


What is the difference between (1,2,3) and [1,2,3] ?



IIRC one is a list, the other a reference to a list --- which in perl6  
will be hidden for the most part. so practically speaking the  
difference is minimal.


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
electrical and computer engineering, carnegie mellon universityKF8NH




Quick question: (...) vs [...]

2008-08-08 Thread John M. Dlugosz

What is the difference between (1,2,3) and [1,2,3] ?

--John