Ok, this is basically a repost of a part of Re^3: [Perl 6] Object methods on the fly?, in which I probably asked too many further side questions, all of which OT wrt the main thread. So I'm asking again here in the hope that it will have more visibility...
Taking as a basis the code TimToady posted in Re^2: [Perl 6] Object methods on the fly? just adding a my to make it a declaration:
my @array does role { method insert ($x) { @.push($x) unless any(self) eqv $x; } };
I though it would been nice to also initialise it, which is possible as I found rather than reading the docs as I probably should have, by trial and error under pugs:
my @array does role { method insert ($x) { @.push($x) unless any(self) eqv $x; } } = 1..5;
But to be fair this was not the first attempt, the latter really being with the assignment directly to the right of @array, which didn't work. OTOH although I can understand why the other way it's more consistent and why the proposed way it would be harder even to parse, or necessarily require parens, for one thing, I'm also sure most people would find it to be more intuitive, while as it is now I suspect most would just say: "for clarity, initialize it in a separate statement."
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: [Perl 6] Initialization within complex declarations
by TimToady (Parson) on Jul 25, 2007 at 00:18 UTC | |
by ambrus (Abbot) on Jul 25, 2007 at 11:08 UTC | |
|
Re: [Perl 6] Initialization within complex declarations
by ambrus (Abbot) on Jul 24, 2007 at 09:04 UTC | |
by blazar (Canon) on Jul 24, 2007 at 22:05 UTC | |
|
Re: [Perl 6] Initialization within complex declarations
by moritz (Cardinal) on Jul 25, 2007 at 11:46 UTC |