"pass by reference" instead of "pass by reference"

"pass by reference" instead of "pass by reference"

Post by Richard Ow » Wed, 12 Nov 2008 23:04:33

I'm not sure if my terminology is correct, been >40 yrs since I've had a
formal programming course.

As I understand it, when Scilab calls a function it makes local copies
of the passed parameters. Normal practice if one needs to have
read/write access to a variable in the calling program is to declare a
variable to have the "global" property.

One could write

[var1, var2] = my_func(var1, var2)

But if var1 and var2 a large arrays that seems to waste memory space.
and processor cycles copying an array from location to location. Also,
in the case that triggered the question, elements could be appended to
each array on any call. That would put an additional load on whatever
memory management is internal to Scilab - thus increasing processor load.

"pass by reference" instead of "pass by reference"

Post by Enrico Seg » Wed, 12 Nov 2008 23:23:38


# local variables inherited from upper levels can be read with no
overhead; but if they are written, a transient local with the same
name is created...
# argument passing is thus by value, in common programming terms;
however, as in 3., the value is not really copied unless needed; for
reading only, passing is by reference. So to say, it is a "lazy"
passing by value, as copying the value is delayed to when really
needed in the progam flow.

#only for adequately written primitives and interfaces of primitives,
there is an option of by value/by reference (see intppty)


"pass by reference" instead of "pass by reference"

Post by Richard Ow » Thu, 13 Nov 2008 01:05:47

I suspected as much. I had seen the first two paragraphs somewhere.
Followed links to intppty. Doesn't look worth the effort in this case.