[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to tell a function from a string
From: |
Jim Van Zandt |
Subject: |
Re: How to tell a function from a string |
Date: |
Tue, 20 Jan 1998 09:08:38 -0500 |
On 17-Jan-1998, Lorenzo M. Catucci <address@hidden> wrote:
| In the comments after definition of newtroot, in Octave's manual, I read:
|
| < any serious code would check
| < the number and type of all the arguments, ensure that the supplied
| < function really was a function, etc.
|
| Now, since I didn't find an is_function() function, I'd like to know how
| must I act to make sure what was passed as a function name is really
| registered with the parser (or can be registered) as a function.
I also thought the documentation could have been more helpful.
Eventually I found this:
- Built-in Function: exist (NAME)
Return 1 if the name exists as a variable, 2 if the name (after
appending `.m') is a function file in the path, 3 if the name is a
`.oct' file in the path, or 5 if the name is a built-in function.
Otherwise, return 0.
and decided that "exist(NAME) > 1" was a reasonable test. (Can it
ever return 4?)
I'm now surprised to read JWE's reply:
> Unfortunately, there isn't a good way to do this from Octave, though
> you could probably wrap is_valid function from src/variables.cc in a
> DEFUN easily enough.
What's wrong with the above test?
Also, please add a discussion to the above passage in the manual.
Maybe something like this:
if (exist(fname)<2)
error("newtroot: expecting function argument");
endif
...
ensure that the supplied function really was a function, etc.
The test in the example is helpful, but fails if...
...or explain why this test is hopeless, or whatever.
- Jim Van Zandt