On Wed, Nov 14, 2007 at 08:09:31PM -0600, Jonathan Scott Duff wrote: : On Nov 14, 2007 2:47 PM, Nicholas Clark <[EMAIL PROTECTED]> wrote: : : > On Sat, Sep 08, 2007 at 01:48:39PM +0100, Nicholas Clark wrote: : > > Have I got this correct? : > > : > > state @a = foo(); # Implicit START block around call and : > initialisation : > > state (@a) = foo(); # Implicit START block around call and : > initialisation : > > (state @a) = foo(); # foo() called every time, assignment : > every time : > : > Um. That seemed to scare everyone away. If it's rephrased like this: : > : > my @a = foo(); # What context is foo called in? : > my (@a) = foo(); # What context is foo called in? Is it the same? : > (my @a) = foo(); # What context is foo called in? Is it the same? : > : > Are the three calls in the same context? Or two (or even three) different : > contexts? : > : : My two cents: foo() looks like it's always in list context, but as far as : START goes, I'd think the first two call foo() only once while the third : calls it every time (just as you have it written). : : Now, someone tell me if I'm right or wrong and why :-)
You're right because you spoke first and nobody contradicted you. :) Actually, the reasoning is that in the first two cases the state declaration counts the subsequent = as part of the declarative syntax and transforms it into a pseudo-assignment with the declaration's semantics, while in the last case the declaration ends when it hits a right parentheses, so the outer = must be normal assignment. In short, a declaration is really a kind of funny macro syntax that just happens to use something resembling the assignment operator to separate its initializer argument (if any), which in the case of C<my> happens to have the same semantics and timing as ordinary assignment. For other declarators, it's still a kind of assignment, but it may happen at some other time more appropriate to the lifetime of the declared variable. (One could argue that C<our>'s current semantics are wrong, and that maybe it should also initialize only at START time, if not earlier. And perhaps disallow multiple initializers.) Larry