in reply to Assignable Subroutines
It strikes me that the thing that prevents validation of values assigned to lvalue subs, is the way in which the lvalue is determined--by being the last line/value of the sub.
If there were a keyword that allowed the programmer to indicate what the lvalue was, he could choose where in the sub that lvalue was positioned and control could be returned to the sub after the assignment has taken place.
sub thing { my( @args ) = @_; ... code to determine what the lvalue should be. LVALUE{ $lvalue }; if( $lvalue eq some condition ) { ... take positive action; } else { ... take negative action; } }
In use, the interpreter would run the code until the (or a?) LVALUE statement is encountered. This is directly equivalent to the current situation of running the sub to determine the lvalue. Once obtained, the LVALUE would be available to the calling code to use in whatever manner. Once the statement that called the sub completes, the remainder of the sub would be run, with the assigned value in place for veryification or whatever else the programmer might wish to do to it.
There are probably a gazillion reasons why this won't work, but it seems to address most of the issues raised, whilst providing for inline, intuative validation.
The main advantage I see of this over tieing, is that the validation code is at the same scope as the the lvalue determination code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Assignable Subroutines
by Aristotle (Chancellor) on Jan 26, 2005 at 02:33 UTC | |
by BrowserUk (Patriarch) on Jan 26, 2005 at 11:10 UTC | |
by Aristotle (Chancellor) on Jan 26, 2005 at 14:17 UTC | |
by BrowserUk (Patriarch) on Jan 26, 2005 at 15:12 UTC | |
by Aristotle (Chancellor) on Jan 26, 2005 at 16:11 UTC | |
|