Inline:

On Fri, Oct 11, 2019 at 8:33 PM ToddAndMargo via perl6-users
<perl6-us...@perl.org> wrote:
>
> On 10/11/19 8:09 PM, William Michels via perl6-users wrote:
> > Hi Todd, Per the REPL, $x looks to be a List:
> >
> > mbook:~ homedir$ perl6
> > To exit type 'exit' or '^D'
> >>
> >> my $x = (44,66)
> > (44 66)
> >> say $x.WHAT
> > (List)
> >> say $x.^name
> > List
> >>
> >> my $y = < 55 77 >
> > (55 77)
> >> say $y.WHAT
> > (List)
> >> say $y.^name
> > List
> >>
> >> say $*VM
> > moar (2019.07.1)
> >
> > HTH, Bill.
> >
> >
>
> >>> HTH, Bill.
> >>
> >> Sweet.  Love examples.  Thank you!
> >>
> >> Question:  what type is "my $x = (44, 66)".   An array?
>
>
> $ p6 'my List $x = (44,66); say $x;'
> (44 66)
>
> :-)
>

#REPL Below:
> my $z = 2,4,6,8;
(2 4 6 8)
> say $z.WHAT
(Int)
> say $z.^name
Int
> say $z.List.WHAT
(List)
> say $z.List.^name
List
>

With the code above, you might be convinced you've created a $z scalar
holding the values (2 4 6 8) that can be coerced to a list whenever
you desire. You'd be incorrect though:

> my $z = 2,4,6,8;
(2 4 6 8)
> say $z
2
> say $z.WHAT
(Int)
> say $z.elems
1
> my $a = (2,4,6,8);
(2 4 6 8)
> say $a
(2 4 6 8)
> say $a.WHAT
(List)
> say $a.elems
4
> say $*VM
> moar (2019.07.1)

I guess parentheses are important in Perl 6.
Some references here (may be in need of updating):
https://docs.perl6.org/language/list
https://stackoverflow.com/questions/34997353/what-type-are-lists-of-any-type-in-perl-6
https://stackoverflow.com/questions/34997670/how-is-this-perl-sensical-considering-perl-6s-type-system

HTH, Bill.

Reply via email to