From help-octave-request at bevo dot che dot wisc dot edu Tue Jan 20 08:08:49 1998 Subject: Re: How to tell a function from a string From: Jim Van Zandt To: "John W. Eaton" cc: "Lorenzo M. Catucci" , help-octave@bevo.che.wisc.edu Date: Tue, 20 Jan 1998 09:08:38 -0500 On 17-Jan-1998, Lorenzo M. Catucci 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