> On Sun, Feb 23, 2003 at 11:12:18AM +1300, Martin D Kealey wrote:
> > I would like to argue in favour of "pass by value" to be the
> > default in the absence of some explicit prototype, because it
> > allows greater type-safety, and because the opposite default
> > interacts badly with out-of-order execution such as parallelism,
> > and bars some optimisations that can be applied to closures. (We
> > do want Perl to run fast on parallel hardware, don't we?)
> 
> Based on what I remember of reading apocalpyses 1 to 5 and messages
> on this list, perl6 intends to pass by value by default.

No, default is constant reference, from Apocalypse 4, under RFC 89.
Well, it's constant reference for I<declared> parameters.  When you
don't give a parameter list, @_ is bound to the argument list with
mutable reference elements, to make it as much like Perl 5 as
possible.  But you shouldn't use that form anyway, because it's
archaic and ugly.

And I don't see how making parameters passed by constant reference is
slow.  If you're writing very close to "pure functional" like you say,
you shouldn't be modifying your parameters anyway.  And constant
reference may have a few consequences with threading that are absent
with by-value if you're not aware of the semantics, but it is a much,
much better default for single threaded programs.  I suspect 90% of
Perl 6 programs will be single threaded.

If you want to modify a parameter in place, you declare with C<is rw>.
If you want to pass by-value, there might be a property for that, but
I think this was recommended:  

    sub foo($bar_) {
        my $bar = $bar_;     # Copy, not bind
        # ... with $bar 
    }

Luke

Reply via email to