stevan / p5-mop-redux

A(nother) MOP for Perl 5
139 stars 36 forks source link

Attributes should be accessible in has initializers #135

Open stevan opened 10 years ago

stevan commented 10 years ago
11:25 phaylon: reminds me: I was wondering if `has $!x = 23; has $!y is lazy = $!x` should work
11:43 ilmari_: given that the initialiser has access to $self (via $_), attributes should work too
11:44 ilmari_: has $!x is ro = 23; has $!y is lazy = $_->x; # shoul definitely work
11:44 rafl: almost certain it doesn't currently, but i can't see a reason why it shouldn't or couldn't
11:44 ilmari_: but = $!x is nicer
11:45 doy: rafl: lazy initializers do, it's a bit weird
11:46 phaylon: ilmari_: plus, it would be odd having to have an accessor just for attribute inter-dependencies :)
11:46 rafl: i meant the the twigils in the defaults
11:46 doy: ah, right
11:46 ilmari_: phaylon: yeah
11:46 ilmari_: phaylon: I meant it should work now, afaict
11:47 doy: yeah, i think it should probably work, but i think it'd be weird if it worked but $self didn't
11:47 doy: getting the invocant from $_ is weird, i think
11:47 phaylon: yeah
11:50 ilmari_: OTOH the initialisers have no (explicit) lexical scope for $self
11:50 doy: making an implicit one wouldn't be hard
11:55 stevan: has $!x = 10; has $!y is lazy = $_->get_x; method get_x { $!x }
11:55 stevan: I think it will be very odd to depend on just an attribute
11:55 stevan: has $!x = 10; has $!y is lazy = $!x + 10;
11:55 stevan: maybe something like that
11:55 stevan: but builders will work and not require any extra accessors
11:58 doy: builders will work, but it does seem like it could be simpler
11:58 phaylon: stevan: more thinking about stuff like `has $!label = die "Label me!"; has $!widget is lazy = LabelWidget($!label)`
12:01 phaylon: which is something I do quite often
12:48 stevan: phaylon: yeah, I was thinking that too
12:48 stevan: has $!classname is required; has $!thing is lazy = $!classname->new;
12:49 stevan: someone should make a github issue :)
12:49 stevan does it
Ovid commented 10 years ago

I'm definitely in favor of this. I've already been bitten by it as it seems natural to allow this.