develooper Front page | perl.perl6.language | Postings from September 2002

Re: Paren madness (was Re: Regex query)

From:
John Williams
Date:
September 23, 2002 22:54
Subject:
Re: Paren madness (was Re: Regex query)
Message ID:
Pine.LNX.4.33.0209232228390.16590-100000@sharkey.morinda.com
On Mon, 23 Sep 2002, Trey Harris wrote:
>
> So then, I think if there's just some clarification about how one-tuples
> are formed, I think everything I wrote in my earlier mail can DWIM
> correctly.  There seems to be no magic here, quotations from LoTR to the
> contrary. :-)

Your post was very helpful to pull us back to sanity.

Allowing list context to create a 1-item list out of a scalar makes sense
in my mind.  (ie  @a = 7  sets @a[0] to 7).

~ John Williams


P.S.  Caution: this way lies madness...

In perl5, to get the 'x' repetition operator to do a list repeat, it
must be in list context _and_ the left side must be in parenthesis.  Will
this strange combination of syntactic context and semantic context still
apply in perl6?  Would it be simpler if it only relied on the scalar/list
context?

After testing various cases of x, I came up with one that I cannot
explain.  Can someone tell me what is happening here (in perl5)?

$ perl -le 'print "@{[ $a = ('a','b') x 3 ]}"; print $a'
a bbb
bbb

or in other words, after evaluating "@a = $a = ('a','b') x 3",
$a is 'bbb' and @a is ('a','bbb') !




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