Calling Conventions and Pass By Reference

Yuval Kogman nothingmuch at
Tue Sep 2 19:43:32 BST 2008

On Tue, Sep 02, 2008 at 19:18:38 +0100, Simon Wistow wrote:
> A thought - what would the advantages and disadvantages of having only 
> references in a language.

I'm going to assume you mean low level referencing semantics (value

> The downside is that, of course, you can spooky actions at a distance - 
> "I passed in this url to this library and it came back relative rather 
> than absolute, wtf?".

The workaround for that is to have parameters be immutable aliases
by default, and only allow writing if explicitly asked for.

Similarly all dereferencing of a readonly value returns a read only
alias to its innards.

It's the symbol itself that is readonly, and not the data.

> I suppose then you'd have to have really good, COWed deep cloning 
> available which is not a hugely difficult goal (In general, I'm not 
> talking about whether or not it's hard to retrofit into an existing 
> language).

I don't think so... The diff is usually that

	my $x = $foo

becomes a binding, not an assignment. This is actually less work for
the compiler. (in perl every assignment involves a copy of some
structure into a new container)

Thins like this:

	$foo = $foo . "bar";

no longer work in the same way.

For 90% of the cases this makes no difference, but does affect

	my $x = "foo";
	my $ref = \$x;
	$x = $x . "bar";
	$$ref; # still "foo"

but conversly you have:

	my $x = 3;
	my $y = $x;
	$y; # 4

IIRC python works like that.

  Yuval Kogman <nothingmuch at>  0xEBD27418

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
Url :

More information about the mailing list