Re: assignable mutators (S06/Lvalue subroutines)

2008-06-16 Thread TSa
HaloO, David Green wrote: I would expect all of those to work the same way in either case. That is, anywhere the sub is used as an lvalue, it could pass the rvalue as a special arg, not just when using =. I agree. But I want to stress that the big thing is that a lvalue sub---and to a

Re: assignable mutators (S06/Lvalue subroutines)

2008-06-06 Thread David Green
On 2008-Jun-2, at 3:30 pm, Jon Lang wrote: sub foo($value?) is rw($value) { ... } Or something to that general effect. The parameter in question must be optional and cannot have a default value, so that a test of whether or not the parameter is actually there can be used to determine

RE: assignable mutators (S06/Lvalue subroutines)

2008-06-03 Thread Kealey, Martin, ihug-NZ
If a routine is rw, you may optionally define a single slurpy scalar (e.g., '*$value') in its signature. A good start, but why limit the Lvalue to a scalar? A list l-value seems like a pretty useful thing to me. -Martin

Re: assignable mutators (S06/Lvalue subroutines)

2008-06-02 Thread David Green
On 2008-Jun-1, at 1:50 pm, Jon Lang wrote: David Green wrote: [...] assignment should work like passing args when used on a function. Then you can easily do whatever you want with it. [...] If a routine is rw, you may optionally define a single slurpy scalar (e.g., '*$value') in its

Re: assignable mutators (S06/Lvalue subroutines)

2008-06-02 Thread Jon Lang
David Green wrote: Jon Lang wrote: If a routine is rw, you may optionally define a single slurpy scalar (e.g., '*$value') in its signature. This scalar counts as the last positional parameter, much like slurpy arrays and hashes must be declared after all of the positional parameters have

Re: assignable mutators (S06/Lvalue subroutines)

2008-06-01 Thread David Green
On 2008-May-27, at 9:40 am, Dave Whipp wrote: TSa wrote: method inch { yield $inch = $.mm * 25.4; self.mm = $inch / 25.4; } Would you regard that as elegant? That looks functionally incorrect to my eyes: if the caller resumes at the time of the yield

Re: assignable mutators (S06/Lvalue subroutines)

2008-06-01 Thread Jon Lang
Jon Lang wrote: This approach could be functionally equivalent to the proxy object approach, but with a potentially more user-friendly interface. That is, sub foo (*$value) { yadda } might be shorthand for something like: sub foo () is rw { return new Proxy: FETCH = method {

Re: assignable mutators (S06/Lvalue subroutines)

2008-06-01 Thread Jon Lang
David Green wrote: It seems overly complex to me, but perhaps I'm missing good reasons for such an approach. I see lvalue subs mainly as syntactic sugar: foo(42); # arg using normal syntax foo == 42; # arg using feed syntax foo = 42; # arg using assignment

Re: assignable mutators (S06/Lvalue subroutines)

2008-05-28 Thread TSa
HaloO, Dave Whipp wrote: The sequence I was thing of is: my $obj = Length.new; $obj.mm = 42; say $obj.inch; # your Length.inch method yields $obj.mm = 63; say $obj.inch; # Length.inch to resumes, overwriting $obj.mm back to 42 It seems to me that the assignment within your inch method will

Re: assignable mutators (S06/Lvalue subroutines)

2008-05-27 Thread Dave Whipp
TSa wrote: class Length { has Num $.mm is rw = 0; method inch { yield $inch = $.mm * 25.4; self.mm = $inch / 25.4; } } Would you regard that as elegant? That looks functionally incorrect to my eyes: if the caller resumes at the time

Re: assignable mutators (S06/Lvalue subroutines)

2008-05-27 Thread Dave Whipp
TSa wrote: TSa wrote: class Length { has Num $.mm is rw = 0; method inch { yield $inch = $.mm * 25.4; self.mm = $inch / 25.4; } } Would you regard that as elegant? That looks functionally incorrect to my eyes: if the caller resumes

Re: assignable mutators (S06/Lvalue subroutines)

2008-05-26 Thread TSa
HaloO, John M. Dlugosz wrote: I have similar thoughts. I'm thinking that some macros will aid in writing proper setters via a tie-like mechanism that don't require any core language changes, so it's not a real problem. That is, a reusable proxy class that you can construct to run the setter

Re: assignable mutators (S06/Lvalue subroutines)

2008-05-26 Thread Brandon S. Allbery KF8NH
On 2008 May 26, at 10:19, TSa wrote: John M. Dlugosz wrote: I have similar thoughts. I'm thinking that some macros will aid in writing proper setters via a tie-like mechanism that don't require any core language changes, so it's not a real problem. That is, a reusable proxy class that

Re: assignable mutators (S06/Lvalue subroutines)

2008-05-26 Thread TSa
HaloO, I wrote: I wonder if that couldn't simply be method attr is rw { return self.blahh; } Or am I missing something? Hmm, I forget something along the lines of method attr ($rhs) { if $rhs 10 { return self.blahh } else { return

Re: assignable mutators (S06/Lvalue subroutines)

2008-05-26 Thread TSa
HaloO, Brandon S. Allbery KF8NH wrote: What if you want to store a modification of the value? e.g. compatibility method to set a length in inches when the stored length is in millimeters. As outlined in my afterthought: class Length { has Num $.mm is rw = 0; method inch

Re: assignable mutators (S06/Lvalue subroutines)

2008-05-16 Thread John M. Dlugosz
Brandon Allbery allbery-at-kf8nh.com |Perl 6| wrote: S06/Lvalue subroutines: Lvalue subroutines return a proxy object that can be assigned to. (...) S13/Methods: Setter methods that expect the new value as an argument do not fall into the well-behaved category, however. When I take these