I'm just wondering... since subroutines in Perl 6 are (like everything else) objects, whether state variables could be considered as public attributes, thus having an accessor, as in:
sub collect (Int *@nums) { state @data; @data.push(@nums); } # prepopulate it as late as possible: &collect.data.push(get_some_values); # ... # use collect(); my @collected = &collect.data;
Before anyone points it out: yes, I know that the example is trivial and there are OWTDI. Yet it's all about some syntactic sugar, and I don't know you, but I like it sweet. It also seems reliable enough to me but possibly for the clash with predefined methods, but there must an elegant and consistent way around...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: [Perl 6] State variables as public attributes?
by moritz (Cardinal) on Aug 26, 2007 at 20:26 UTC | |
by blazar (Canon) on Aug 26, 2007 at 21:46 UTC | |
by moritz (Cardinal) on Aug 27, 2007 at 06:57 UTC | |
by blazar (Canon) on Aug 27, 2007 at 17:43 UTC |