Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion * vs **
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Paul  
View profile  
 More options Apr 23 2003, 9:48 am
Newsgroups: perl.perl6.language
From: ydbx...@yahoo.com (Paul)
Date: Wed, 23 Apr 2003 06:47:05 -0700 (PDT)
Local: Wed, Apr 23 2003 9:47 am
Subject: Re: * vs **

--- Larry Wall <la...@wall.org> wrote:

> On Tue, Apr 22, 2003 at 02:51:46PM -0700, Paul wrote:
> : S6:
> : ===
> : <quote>
> : The unary prefix operator * flattens its operand (which allows
> : the elements of an array to be used as an argument list). The *
> : operator also causes its operand -- and any subsequent arguments
> : in the argument list -- to be evaluated in list context.
> :
> :    sub foo($x, $y, $z) {...} # expects three scalars
> :    @onetothree = 1..3;       # array stores three scalars
> :
> :    foo(1,2,3);               # okay:  three args found
> :    foo(@onetothree);         # error: only one arg
> :    foo(*@onetothree);        # okay: (array) flattened to 3 args
> :
> : The * operator flattens lazily -- the array is only flattened if
> : flattening is actually required within the subroutine. To flatten
> : before the list is even passed into the subroutine, use the unary
> : prefix ** operator:
> :
> :  foo(**@onetothree);    # array flattened before &foo called
> :
> : </quote>
> : ===
> :
> : So is ** actually a seperately implemented operator, or is that the
> *
> : op working on the return from the * op, like the way Larry
> : suggested the ref-of-ref operator, \\ ? :)

> Er, that was a joke...

yeah, I know. And I know ** was not. I was just wondering out loud
about how it would work in more detail, and phrased it horribly as
usual. :)

> * and ** are identical insofar as they defeat signatures and impose
> list context on the rest of the arguments in the list.  The only
> difference is that for ** there's an extra internal call to flatten()
> or some such that un-lazifies anything lazy in the list.
> Larry

See? That makes me think that **@x is similar to *(*(@x)).
Similar, but still implemented seperately? Or is using the one
effectively like using the other aside from precedence twiddling with
the parens?

Either way, the important things to know:
 - both flatten
 - ** prevents laziness

Hmm, maybe I should put one of those on my shopping list next to the tuits....

__________________________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo
http://search.yahoo.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.