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: John W. Eaton
Subject: Re: Realtime cost of call by value
Date: Fri, 31 Oct 2003 12:33:25 -0600

On 31-Oct-2003, address@hidden <address@hidden> wrote:

| Just FYI, many high-level languages ( I'll use Scheme as an example )
| don't EVER pass variables to functions via call-by-value, but
| call-by-reference. I'm talking about the interpreter, *not* the actual
| language. What this means, is that for any level of nested function
| calls, and for any number of arguments, there isn't a heavy
| performance penalty for large arguments. So even though it might look
| like you're just flat-out passing off a huge variable, internally only
| the scoped reference to that variable is being manipulated.

?

This is somewhat off topic, but...

If I do something like

  (define foo (lambda (s) (set! s -9999) s))
  (define s1 1)
  (foo s1)
  s1

only the local variable a will be changed (at least .  The top-level variable b
will not change.  So somewhere, a copy is made (or a new definition is
given to a variable), even if the argument is passed by reference.

OTOH, if I write

  (define foo (lambda (v) (vector-set! v 1 -9999) v))
  (define v1 #(1 2 3))
  (foo v1)
  v1

then you will see that the local variable v and the top-level variable
v1 both change.  (This is like the mutable and non-mutable objects
that Python has as well.)

This is NOT the way that Octave is defined to function, because that
is not the way the Matlab works.  So, this might be great in some
respects, but there is no way we can change this behavior in Octave.

Also, it seems somewhat bad to me that you have to keep track of which
kinds of objects have this special mutable property.  I suppose people
get used to it, but if you are familiar with Octave/Matlab
programming, it would seem to me that it could cause some trouble.

| What this kinda requires of the language, though, is some sort of
| formal bookkeeping of variable scope.

?

I think that is kinda required by just about any language.

| It isn't that hard to implement a lexical scope. I'd recommend "The
| Structure and Interpretation of Computer Programs" for a good, clean
| explanation of how to achieve just this:
| 
| http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-26.html

That's fine, but how is it going to help Octave?

jwe



-------------------------------------------------------------
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]