Thu 09 Dec 2010 06:52:26 PM UTC, comment #1:
The demo function creates a string that wraps all of the demo code in a function called _demo_, evals that string to create a function, then calls _demo_. In the olden times, the nested functions weren't treated as nested or subfunctions, so they were installed globally. And the type function was a built-in function that could reconstruct and display functions that were not defined in files (by reconstructing the program text from the parse tree information). Now we have subfunctions and the type function is a .m file that can't seem to handle anything but files.
Note this simpler examples of failure (save the fucntion to a file and execute the primary function):
For this, I see exist returning 2 (function from a file) but type can't print it because it doesn't know anything about how to find the subfunction.
I'm not sure what the right behavior is.
What does Matlab do for this function? Is there a way to find out if a subfunction exists? I guess the question doesn't make much sense if you think of subfunctions as private and that they are statically defined (so there is really no need to ask). What about the type function? Does Matlab have any way to display the text of a subfunction that is in scope?
What should Octave do, given that it is already different from Matlab in that it allows functions to be constructed at the command line and by evaluating a character string?
Should we just rewrite demo instead of trying to fix Octave so that the current demo code work?
Even if we just avoid the problem by rewriting the demo function, we may still have some issues to deal with. I noticed some crashes when I was trying to debug what was happening. For example, removing the "type build_orig" and "type build" lines from the first speed demo, then running "demo speed" caused a crash for me.
|