Well, this feature could still be implemented with a coroutine.
Agreed, it could. Indeed, that has some interesting possibilities for allowing the creation of tranparent coroutines.
There is indeed effectively no difference between your proposition and tieing. So why invent a new special-use mechanism rather than streamlining an existing one that can do the same job and more besides?
First, I would contend there is a significant difference. I have an attribute. I wish to control the values that can be assigned to that attribute (whether that attribute is externally exposed or only settable from with the class definition).
The language allows me to have a method with the same name as that attribute. The obvious place to encapsulate all interactions with that attribute, is within that method. Scattering the decision as to what value will be set by assignments to the method, and the code to validate those assignments, into lots of little code blocks makes for complexity that should be avoided.
Equally, if the lvalue in question is an array or hash, or a splice across one or the other, then recieving the values one at a time through the STORE method of a tied array makes for horrible problems.
What if the validation criteria is that all the values in the list being assigned must be unique? Now I have to add additional (global) temporary variables in order that I can view the data as a single list in order to verify it. But how will I know when I have recieved the last value? And what happens if I reject the attempted list assignment? How does the recieving code get that notification? What does it do with it?
Even if the assignment is a scalar lvalue. When the FETCH method is called, will it recieve the (variable number of?) parameters passed from the calling code that are required to determine the lvalue to use? (Think substr( $self, $offset, $length ) = $str; here!)
And if it does, and so the substring is assigned, now I want to validate that assignment. Will the same parameters as were passed to the FETCH be available to the STORE? If not, that again means that the programmer has to make provision for temporary (global) storage to retain those values between the calls to the FETCH and the STORE.
The "example code" shown that outlines the inline tie mechanism shows a TEMP method. This is provided in order to allow lvalue subs to be temporised. What happens if the programmer doesn't provide a TEMP method? Does that mean that this method cannot be temporised? Or will the system provide a default TEMP method?
Assuming the programmer does provide a TEMP method, what should it do? Provide a temporary lvalue that will not affect the actual attribute? Then if the TEMP value is never realised, then code will never call the STORE and that temporary value will what? When will the programmer know he can discard it?
And if it is realised, when the STORE method is called, how will I know that I have to copy the value from the temporary lvalue I returned from the TEMP method ? In other words, how will the STORE method know when the value being STOREd was assigned to an lvalue provided via the FETCH method and when it has been assigned to an lvalue provided by the FETCH method? More global flags for communicating this information between these disparate methods?
And I haven't even begun to consider the implications for multi-thread code where the FETCH and TEMP methods could be called several times before a STORE method is called. That would make the problem of trying to coordinate the cross-call, global metadata impossible.
It may well be that all this has been thought about and resolved--but if it has, it certainly isn't obvious from the Apos and Syns.
Most such validation should really be done by the subtype system in Perl 6.
Anyone who remembers writing Pascal and having: