help-octave
[Top][All Lists]
Advanced

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

calling a function within a multi-function file


From: John W. Eaton
Subject: calling a function within a multi-function file
Date: Wed, 4 May 2005 14:29:15 -0400

On  1-May-2005, Brian Blais wrote:

| If I have the following function file test.m
| 
| function y=test(x)
|    y=x;
| endfunction
| 
| function y=test2(x)
|    y=2*x;
| endfunction
| %------------------------------
| 
| 
| Is there a way to call function test2 directly, even though it is in
| test.m?  I could use the source command, but then I have to do that
| manually every time I change the file.  Is there another way?

If you use a subfunction instead (i.e., omit at least the first
"endfunction" in your file) then you can write

  feval ("test:test2", x)

but obviously

  test:test2 (x)

won't work because test:test2 is parsed as a range.  Perhaps we should
use "$" as the separator here instead of ":", and then make "$" a
normal character that can appear in identifiers?  Then you should be
able to call test$test2 (x).  But is that really what we want?  One of
the reasons for defining subfunctions is to make them private.

But currently, even using feval to call the function will not do quite
what you want because Octave does not seem to notice when the file has
changed unless, after modifying the file, you call test before test2.
I suppose that might be considered a bug.

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]