From help-request at octave dot org Sun Apr 16 07:25:59 2006 Subject: Re: Finding out the name of the dispatched function From: Paul Kienzle To: Shai Ayal Cc: help Help Date: Sun, 16 Apr 2006 08:24:35 -0400 On Apr 16, 2006, at 1:49 AM, Shai Ayal wrote: > My question was not clear -- consider the following example with the > theoretical function HowWasICalled: > > function xxx > disp(["--> ",HowWasICalled()]); > endfunction > > dispatch("yyy","xxx","any"); > dispatch("zzz","xxx","any"); > > xxx > --> xxx > > yyy > --> yyy > > zzz > --> zzz > > > Is the a function which does what HowWasICalled does? A function like > this would allow a single function to be reused. An immediate example > which springs to mind is a generic warning function: > > function gen_warn > warning("%s is depreciated\n",HowWasICalled()); > endfunction > > dispatch("set","gen_warn","any"); > dispatch("gset","gen_warn","any"); > > > and so on No, this is not supported. Nor do I see an easy way to support it. You could hack dispatch.cc so that it would do the right thing when the function is called via dispatch by pushing the variable 'base' before dispatching in dispatch.cc(do_multi_index_op) and popping it after return. Then HowWasICalled could return the top of this stack. However, this would not return the correct result if not called via dispatch, and would slow down dispatch even if the facility wasn't used. - Paul ------------------------------------------------------------- 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 -------------------------------------------------------------