help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: overloading functions (Was: Indirect Addressing Question)


From: adler
Subject: Re: overloading functions (Was: Indirect Addressing Question)
Date: Fri, 16 Nov 2001 21:20:37 -0500 (EST)

On Fri, 16 Nov 2001, John W. Eaton wrote:
> On 16-Nov-2001, Paul Kienzle <address@hidden> wrote:
>
> | Matlab decides what function to call based on the type of the
> | first argument, which can be done reasonably cheaply and
> | handles the majority of the cases.
>
> This kind of design decision is what bugs me about Matlab, I think.
> "It will work most of the time.  Users won't be too bothered when it
> fails.  After all, we don't expect anyone to actually notice the
> inconsistency because it will come up so infrequently."

Here is another idea (with different benifits and problems).

If a function could install a handler which sits "in front" of
currently defined functions, much like TSR type device drivers
did in DOS.

Example:

   function y=sum(x)
   # do sparse sum - overload current sum
   if is_sparse(x)
      y= calulate_sparse_sum(x)
   else
      give_up_and_go_to_covered_function
   end

Here give_up_and_go_to_covered_function would throw
away any calculations and call the lower layer function.

Another implementation:

   function y=sum(x)
   # do sparse sum - overload current sum
   if is_sparse(x)
      y= calulate_sparse_sum(x)
   else
      y= feval(__OVERLOADED_FUNCTION__, x);
   end

Where __OVERLOADED_FUNCTION__ is dynamically
defined to call the lower layer function.


Advantage:
   Can be done without any OO infrastructure

Disadvantages:
   Slower than function lookup
   Can be inconsistent if multiple overlay functions
      are loaded in a different order.

Comments...
_______________________________________
Andy Adler,                address@hidden



-------------------------------------------------------------
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
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]