Calling Conventions and Pass By Reference

Raphael Mankin raph at mankin.org.uk
Tue Sep 2 21:07:18 BST 2008


On Tue, 2008-09-02 at 20:13 +0100, Simon Wistow wrote:
> On Tue, Sep 02, 2008 at 09:43:32PM +0300, Yuval Kogman said:
> > but conversly you have:
> > 
> > 	my $x = 3;
> > 	my $y = $x;
> > 	$x++;
> > 	$y; # 4
> > 
> > IIRC python works like that.
> 
> There was an interesting paper a while back [goes off to find it ... 
> AHAH]
> 
> http://www.cs.mdx.ac.uk/research/PhDArea/saeed/
> 
> about the cognitive models used when learning to program.
> 
> Students are asked questions like
> 
>     a=10
>     b=4
>     c=a+b
> 
>     What is the value of c?
> 
> 
> And then
> 
>     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. 

I think that you are confusing call by reference with call by name. With
call by name every parameter is actually a subroutine that evaluates the
parameter when you use it, as in Algol 60 of blessed memory.




More information about the london.pm mailing list