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

Re: Regex query

From:
John Williams
Date:
September 22, 2002 22:01
Subject:
Re: Regex query
Message ID:
Pine.LNX.4.33.0209221509290.13964-100000@sharkey.morinda.com
On Sat, 21 Sep 2002, Jonathan Scott Duff wrote:
>
> Why can't perl be smart enough to figure out what we mean?  Something
> along these lines:
>
> 	(7)	# list context
> 	(3+4)	# numeric context (there's a numeric operator in there)
> 	(3+4,5)	# list context (comma trumps the numeric op)

My understanding of context (which admittedly, may be completely
incorrect) is that context is imposed from the outside.  So in (3+4), 3
and 4 are in numeric contect because the '+' says so, but we can't tell
what context (...) is in, because there is no context.  + has higher
precendence than comma, so the 3+4 becomes 7 before the comma creates a
list: 7,5.

A different workaround just occurred to me for perl6.  Maybe instead of
(7) having list context imposed by the parenthesis, imposing list context
on a scalar automatically creates a 1 item list.  So:

   @a = (7);

is the same as

   @a = 7;

And actually, that works in perl5 too.

So maybe we're arguing about nothing?


> (7,) is an abomination.  It's one of python's misfeatures that annoys
> me the most.

Strangely enough, it's one of the features of perl that I really like,
although you have to think of it in the context of
(
 	'a',
	'long',
	'list',
	'of',
	'items',
	'one',
	'per',
	'line',   # <-- notice the comma!
)

Of course, _requiring_ the comma is bad, but as long as we can use [7] or
rely on list context creating a single item list out of a single item, it
is not required.

~ John Williams




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