In Perl 6, the default parameter passing is to make a read-only alias
for the caller's lvalue. This means that the function may not change
the caller's variable, but must track changes to it made by other means.
What is the point?
It is a contrivance to illustrate how the variable can be changed by
other means, and requires a global variable, the same variable passed as
two different parameters, or the variable and a closure that affects the
variable be passed.
In fact, this effect seems like something that should be warned against,
not something that is touted as a feature.
It complicates the passing, requiring a read-only proxy or equivalent be
introduced, making the readonly parameter more complex than the rw
parameter. It makes the actual access more complex, having to go
through this extra layer. It prevents optimizations, since you have
more plumbing to go through and you have to watch for aliasing (that's
the feature!) instead of assuming the value doesn't change between accesses.
In Perl 5, the @_ is a normal alias (read/write), and most parameters
are copied to local variables, making it essentially pass-by-value. The
local variable is pass-by-value, and looking back at the @_ is pass by
reference. There is no feature like Perl 6's default readonly passing
(read-only reference). So it's not for historical use. At least not as
the default method!
So, I ask: is there any reason to want this read-only reference as a
passing method? And if so, why does that preclude having the simple
pass-by-value method available also?
From the typical Perl 5 usage, I would think that pass-by-value should
be the default.
--John
- Why pass by reference? John M. Dlugosz
-