help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Realtime cost of call by value


From: Geraint Paul Bevan
Subject: Re: Realtime cost of call by value
Date: Mon, 03 Nov 2003 14:37:38 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

John W. Eaton wrote:

|
| Given the above definition of F, you could expect
|
|   F (X);     # OK, pass X by reference.  If F changes A, X also changes.
|   F (1);     # ERROR, reference to constant.
|   F (X+1);   # ERROR, reference to temporary.
|   F (X(1));  # ERROR, reference to temporary.
|

|
| I'm not sure what syntax we should use, but a unary & as above would
| be one possibility that would not be incompatible with Matlab syntax
| (at least currently).
|
| We could also introduce a way to make one variable a reference to
| another apart from argument lists.  Something like
|
|   reference A = B;
|
| or perhaps
|
|   &A = B;
|

| What I'm most interested in now is what the syntax and semantics
| should be, not precisely how it will have to be implemented.
|
| Comments?
|
| jwe
|

I like the idea of creating references to arguments in function calls,
however I'm not over keen on an error being produced for statements such
as F(1) if the argument of F has been declared as a reference. It might
be better to override the reference declaration and implicitly just pass
a temporary value (perhaps with a warning to the user). I can't really
see how any nasty errors would arise as a result of this; if the caller
doesn't  make a variable available, presumably it would not care whether
or not it is passed by value or by reference, i.e. "F(&rand(20,20))" and
"F(rand(20,20))" should probably do the same thing.

I don't understand why F(X(1)) should cause an error in your example.
Why should a function not be able to alter the element of an array? I
can think of examples where it might be desirable to pass some elements
of an array to a function to be processed while ensuring that other
elements are conserved:

index = [1:10]'; data = rand(10,1); m = [index, data];
F(&m(:,2)) # should allow column 2 to be altered but not column 1


I like the idea of creating references to objects other than function
arguments even more. In particular, I would like to be able to create
references to substructures in large data structures and have the
underlying data altered:

for &my_substructure = some.large.data.structure.
manipulate(my_substructure)


As for the notation, the ampersand might be a bit confusing for people
who haven't come across C++ before. Maybe a binary operator such as '->'
would be more intuitive ("A -> B" means "A points to B"). At first I
thought '=>' might be better as it doesn't clash with the C++ use of
'->', but it would probably end up getting confused with '>='.


- --
Geraint Bevan
http://www.mech.gla.ac.uk/~gbevan

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iEYEARECAAYFAj+maDEACgkQcXV3N50QmNMknQCfbmp3NbOAdnwYa1QeaHuG2rVC
vBoAn2qhQbc1NfE9Us7xCiumW04LCIW9
=ClFR
-----END PGP SIGNATURE-----



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]