[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Function names in feval
From: |
John W. Eaton |
Subject: |
Function names in feval |
Date: |
Wed, 22 Mar 2000 03:35:31 -0600 (CST) |
On 22-Mar-2000, Dirk Laurie <address@hidden> wrote:
| In the following Octave code (2.0.14):
|
| function y=integ(f,a,b,n)
| h=(b-a)/n; x=a+h*(0.5:n);
| y=h*sum(feval(f,x));
| endfunction
|
| the string 'f' may not contain the name of any local variable.
| I.e. if I have coded
|
| function y=f(x)
| y=exp(sin(x));
| endfunction
|
| it is illegal to ask for
|
| integ('f', 0, 2*pi, 16)
|
| This means I have to do one of the following:
|
| (a) use local variables with names like f_, h_ etc and tell
| my user not to use such names. Problem: if his routine,
| in turn, has a function argument, he has to think up
| another convention for his own local variables, etc.
|
| (b) make a list of all local variables and tell my user those
| are illegal.
|
| Neither is very satisfactory. However, this must be a common
| problem which must by now have a satisfactory solution.
|
| I'm looking for one of the following answers:
|
| (a) "Set THE_RIGHT_GLOBAL_VARIABLE to 1 and it will ignore
| local variables for feval."
| (b) "Install 2.0.16, in which this problem has been fixed."
| (c) "This is a standard situation, which must be handled as
| follows..."
Sorry, I don't have one of those answers. I can only offer:
(d) This looks like a bug, here is a patch to try.
jwe
2000-03-22 John W. Eaton <address@hidden>
* variables.cc (is_valid_function): Look in the global symbol
table for functions.
--- src/variables.cc~ Sat Jan 29 21:00:58 2000
+++ src/variables.cc Wed Mar 22 03:07:48 2000
@@ -263,7 +263,11 @@
symbol_record *sr = 0;
if (! fcn_name.empty ())
- sr = lookup_by_name (fcn_name);
+ {
+ sr = global_sym_tab->lookup (fcn_name, 1, 0);
+
+ lookup (sr, 0);
+ }
if (sr)
ans = sr->def ();
-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.che.wisc.edu/octave/octave.html
How to fund new projects: http://www.che.wisc.edu/octave/funding.html
Subscription information: http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------