On Wed, 14 Aug 2002, Luke Palmer wrote: > Why? We could make arglists exactly equivilent to the way they're done in > Perl 5, which is a good way. > > sub foo($a, $b, *@c) {...} > > Would be exactly equivilent to Perl 5's > > sub foo { my ($a, $b, @c) = @_; ... }
I've got another idea. How about using a copy-restore technique? First, assume all arguments are pass-by-reference, whether constant or not. Second, allow "is ro" as a modifier to force constant semantics -- in this case, don't make a copy, just use the reference and refuse to modify it. Third, allow "is rw" as a modifier to enable copy-restore, and to make the reference modifiable. Fourth, copy all named parameters into local variables from the passed reference (except for "is ro" parameters, which should be aliased) -- and then keep @_ with the actual references, as in Perl 5. (Unlike Perl 5, the "is ro" parameters would not be modifiable even via @_.) Finally, for "is rw" parameters, copy the modified local variable back to the referenced parameter (the original one, even if @_ was shifted!), but ONLY for a normal subroutine exit. This would allow pass-by-value semantics by default for convenience, easily forced read-only parameters, pass-by-reference semantics when desired, but with a twist -- if the function aborts (throws an exception), no parameters have been changed, which offers hassle-free transaction-like atomicity. If a function really wants to modify its parameter, despite throwing an exception, it could do so via @_ directly. Or, we could also allow another modifier "is ref" to use simple (modifiable) pass-by-reference semantics, but default to copy-restore for "is rw"... This seems like it could be the best of all worlds -- what do people think? Deven