From bug-request at octave dot org Thu Jun 16 11:50:47 2005 Subject: Re: Precedence of compiled functions From: "John W. Eaton" To: Keith Goodman Cc: bug at octave dot org Date: Thu, 16 Jun 2005 12:46:45 -0400 On 11-Jun-2005, Keith Goodman wrote: | On 6/11/05, John W. Eaton wrote: | > On 11-Jun-2005, Keith Goodman wrote: | > | > | On 6/11/05, John W. Eaton wrote: | > | > On 11-Jun-2005, Keith Goodman wrote: | > | > | > | > | To reproduce: run the command "which func" (or "help func"). Then | > | > | change your path so that a new version of func takes precedence. Now | > | > | do a "which func" and you'll see the old version of func. That's the | > | > | bug: I was expecting to see the new version of func. If you "clear | > | > | func" and then do "which func", you'll see the new version. | > | > | > | > So you want any change to LOADPATH to clear all functions? | > | | > | Not all. Only the ones that point to a different version of the | > | function after the path change. (OK, that sounds difficult to | > | implement but as a user that's the behaviour I expect when I change | > | the path.) | > | > Yes, that's why it would be simpler to just clear them all, though I | > realized after sending the message that you would want to clear only | > those functions that were defined from funtion files (.m or .oct) and | > not those defined on the command line, or maybe from script files. | > This all gets ugly fast, I think. Is this what Matlab does? If so, | > then for complete compatibility, maybe we should also not allow | > defining functions at the command line or in scripts? (No, I don't | > really want to do that, and FWIW, I think that the magic autoloading | > of all functions that Matlab does causes more problems that it | > solves. | | Matlab gives precedence to the first name match in the path, not to | the function you used most recently (as Octave does). If there is a | way to clear all compiled functions without clearing variables then I | can see if there is interest in adding it to addpath and rmpath. | | Or maybe just clear all functions when LOADPATH is changed. Changes to | LOADPATH are relatively rare. I've done a little investigating, and I don't think clearing the functions is the thing to do. We really need to do some work to modify the way the symbol table handles functions. For example, if you have d1/f.m: function f () disp ('this is d1/f'); d2/f.m: function f () persistent x if (isempty (x)) x = 1; else x = x + 1; end fprintf ('this is d2/f, x = %d\n', x); and then start in d1: >> f => this is d1/f >> cd ../d2 >> f => this is d2/f, x = 1 >> f => this is d2/f, x = 2 >> cd ../d1 >> f => this is d1/f >> cd ../d2 >> f => this is d2/f, x = 3 >> clear f >> f => this is d2/f, x = 1 so if we clear functions, we will not do the "correct" thing for persistent data. Instead, we need to leave the function in memory to preserve any persistent local data, and then allow other functions with the same name to be loaded. This will require changing the way functions are stored in the symbol table (d1/f is different from d2/f) and then also changing the way we search for them. 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 -------------------------------------------------------------