[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Realtime cost of call by value
From: |
Per Persson |
Subject: |
Re: Realtime cost of call by value |
Date: |
Sun, 2 Nov 2003 20:42:14 +0100 |
On Saturday, November 1, 2003, at 02:53 AM, John W. Eaton wrote:
I would be interested in a way to pass arguments by reference, but it
must not be the default. Here is a (half-baked) proposal to think
about.
I for one would really appreciate an option to pass arguments by
reference.
(Actually, the idea gives me the same feeling I had on a christmas
morning as a child;-)
Similar to C++, I think the notion of a reference argument should be a
property of the function definition, not the code that calls the
function.
Yes, definitely.
So we would write something like
function F (reference A)
...
endfunction
this is OK,
or perhaps, if you prefer concise and cryptic
function F (&A)
...
endfunction
nope, this is probably very alien to people who doesn't know C++.
to declare that A is passed by reference for all calls to F rather
than something like
[snip]
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).
FWIW, in Objective-C the keywords "byref" and "bycopy" are used to
state how live objects passed between different threads or processes
should behave. Again, this is a property of the method (function) that
receives the message (call) rather the calling statement.
Even with pass by copy as the default, I think it might be of some use
to have a keyword such as "bycopy", which would evaluate to a
whitespace, that _could_ be used for clarity.
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;
would cause A and B to share the same value in memory. If A changes,
so does B, or if B changes, so does A. If you did something like
C = B;
reference A = B;
then changed A, only A and B would change, not C.
I'm not sure about this...
In defining function F(byref A) we state that A is passed by reference,
but
with = interpreted as an assignment one could argue that the construct
should be
A = byref B;
i.e. A is assigned a reference to B.
(I may be completely off here though...)
This part, however, I don't see as important as the option to
explicitly state a function as taking a parameter by reference.
Just my 0.02€
/Per
-------------------------------------------------------------
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
-------------------------------------------------------------