Calling Conventions and Pass By Reference

Randy J. Ray rjray at blackperl.com
Tue Sep 2 20:24:42 BST 2008


>     a=10
>     b=4
>     c=a+b
>     a=20
> 
>     Now what is the value of c?
> 
> For the first example, the answer is pretty clearly 14 but for the 
> second the answer could arguably be either 14 *or* 24.
> 
> I think most programmers are going to go with 14 but I wonder if a 
> totally pass by reference language would cause effects that would mean 
> that you would get used to it being 24. 

Ummm, not unless the value of "c" is actually a representation of the 
expression "a + b" that is dynamically re-interpreted each time you read it. 
Otherwise, even in a reference-only context, "c" was calculated at assignment 
time from the existing values of "a" and "b".

Randy
-- 
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Randy J. Ray                 Silicon Valley Scale Modelers: http://www.svsm.org
rjray at blackperl.com
randy.j.ray at gmail.com


More information about the london.pm mailing list