develooper Front page | perl.perl6.users | Postings from October 2019

Re: Match operator: error with any() junction and user-defined $_topic variable

Thread Previous | Thread Next
From:
William Michels via perl6-users
Date:
October 12, 2019 10:09
Subject:
Re: Match operator: error with any() junction and user-defined $_topic variable
Message ID:
CAA99HCy3KcRHDejf_X521OamyvF+thdp5HWjZ9rn3sD5wZrSKg@mail.gmail.com
Inline:

On Fri, Oct 11, 2019 at 8:33 PM ToddAndMargo via perl6-users
<perl6-users@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.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About