Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: [Perl 6]: Small discoveries VII, Flattening

by QM (Parson)
on Oct 31, 2017 at 10:15 UTC ( #1202406=note: print w/replies, xml ) Need Help??


in reply to [Perl 6]: Small discoveries VII, Flattening

Note the trailing comma.

Which is horribly like some Python I've had to write. I hate it when syntax DWIMs the wrong way.

> python >>> x = (1) >>> x 1 >>> x = (1,) >>> x (1,)

So (1) is not a tuple, but (1,) is?

Back to Perl...

Does the number of trailing commas affect anything? E.g., [[["hello"],,,,],,,,]. (Because in Python it's a syntax error!)

-QM
--
Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re^2: [Perl 6]: Small discoveries VII, Flattening
by Anonymous Monk on Oct 31, 2017 at 14:22 UTC
    So (1) is not a tuple, but (1,) is?
    (1) is a parenthesized expression, not a tuple. Same with (1+1). This is an unfortunate result of having two different meanings for parens.
    Does the number of trailing commas affect anything?
    Consecutive commas are also a syntax error in Perl6.
      Parens don't build lists in Perl6, commas do:
      my @a := 1,2; say @a.^name; #List my @b := 1,; say @b.^name; #List
      Parens are usually needed because of precedence when embedding the List into another expression. The comma does have another meaning: it's the separator in argument lists.
        > my $x = 1,2; say $x 1 > my $y = (1,2); say $y (1 2)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1202406]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2021-04-23 08:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?