perl6-language
[Top] [All Lists]

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

To: "Brandon S. Allbery KF8NH" <allbery@ece.cmu.edu>
Subject: Re: Quick question: (...) vs [...]
From: "Patrick R. Michaud" <pmichaud@pobox.com>
Date: Sat, 9 Aug 2008 14:26:47 -0500
Cc: "John M. Dlugosz" <dhcgnd702@sneakemail.com>, perl6-language@perl.org
Delivered-to: mailing list perl6-all@perl.org
Delivered-to: perl6-all-poster@perl.org
Delivered-to: mailing list perl6-language@perl.org
Delivered-to: perl6-language@perl.org
In-reply-to: <68DADB01-2CE3-46C8-AF4A-D15C04A98014@ece.cmu.edu>
List-help: <mailto:perl6-all-help@perl.org>
List-id: <perl6-all.perl.org>
List-id: <perl6-language.perl.org>
List-post: <mailto:perl6-all@perl.org>
List-subscribe: <mailto:perl6-all-subscribe@perl.org>
List-unsubscribe: <mailto:perl6-all-unsubscribe@perl.org>
Mailing-list: contact perl6-all-help@perl.org; run by ezmlm
References: <18932-80751@sneakemail.com> <68DADB01-2CE3-46C8-AF4A-D15C04A98014@ece.cmu.edu>
User-agent: Mutt/1.5.17+20080114 (2008-01-14)
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


<Prev in Thread] Current Thread [Next in Thread>