Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

is constant eq pass by value (apoc6)

5 views
Skip to first unread message

Uri Guttman

unread,
Mar 10, 2003, 6:03:12 PM3/10/03
to perl6-l...@perl.org

is constant (default)

Every formal parameter is constant by default, meaning primarily
that the compiler won't feel obligated to construct an lvalue
out the actual argument unless you specifically tell it to. It
also means that you may not modify the parameter variable in any
way. If the parameter is a reference, you may use it to modify
the referenced object (if the object lets you), but you can't
assign to it and change the original variable passed to the
routine.

this confuses me. sometimes i want a simple pass by value param which i
can modify locally in the sub. is this the same as the constant above?
if so the name is not the best (even if it is the default and won't be
explicitly used much).

editing suggestion for last sentence:

If the parameter is a reference, you may use it to modify the
referenced object (if the object lets you). If you assign to a
constant param, its value will change inside the sub (like any
other lexical variable would) but the original variable passed
to the routine is never modified. This behavior is well known as
pass by value.

uri

--
Uri Guttman ------ u...@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class

Mark J. Reed

unread,
Mar 10, 2003, 6:08:07 PM3/10/03
to perl6-l...@perl.org
On 2003-03-10 at 18:03:12, Uri Guttman wrote:
> this confuses me. sometimes i want a simple pass by value param which i
> can modify locally in the sub. is this the same as the constant above?
No, that's the same as "is copy".


--
Mark REED | CNN Internet Technology
1 CNN Center Rm SW0831G | mark...@cnn.com
Atlanta, GA 30348 USA | +1 404 827 4754

Uri Guttman

unread,
Mar 10, 2003, 6:08:59 PM3/10/03
to perl6-l...@perl.org

bah, the is copy is pass by value with local modification (my params in
p5).

this works as most params should be constant. the few that are copies
can be declared that or copied to my vars.

i have to wait on posting before i read the whole megilla.

0 new messages