[Top][All Lists]

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

Re: defining types in m-files?

From: pkienzle
Subject: Re: defining types in m-files?
Date: Fri, 29 Aug 2003 22:11:45 +0100

On 27 Aug 2003 at 23:27, Andy Adler wrote:

> On Wed, 27 Aug 2003 address@hidden wrote:
> > Has anyone done any work on defining new types from scripts?
> >
> > If not, is the Matlab API sufficient, or should we define our own?  I
> > haven't seen any code in the wild which uses it, so I don't know
> > that there is a compelling reason for compatibility.
> Do you have a link which explains the Matlab API approach to
> new types? 
A google search for "matlab classes" should work.

> Do you have any oppinions about what it does
> right/wrong?

Some issues are a little strange, such as the need to define
all methods of class t in a subdirectory called @t somewhere
on your path.

Dispatch rules for overloaded functions are complicated.
You need to create a precedence heirarchy so that calling
for example a function like fn(poly,sparse) knows whether
to call the @poly/fn or @sparse/fn (assuming that
both of these exist).

> I had assumend that this would be impossible, so I didn't try.

No, just a bit of grunt work.  Dispatch(...) helps, but it will
need to be extended so that it doesn't matter where in the
argument list the object appears.  Overloading the operators
is just a matter of adding some entries into the op table to
call e.g., poly_plus when one of the arguments to + is a poly.

> But it sure would be a nice feature to have. Especially if
> it would be used in conjunction with something fairly object
> oriented.
> I'm not looking for the inheritance part of OO, just the
> encapsulation. I'd like to do:
> >> obj.data1= 1;
> >> obj.data2= 2;
> >> obj.method1= inline('this.data1 + this.data2');
> >>
> >> obj.method1
> ans = 3

Matlab uses method1(obj), but the '.' operator is overloadable,
so no reason you couldn't make obj.method1 call the
function method1.

Paul Kienzle

Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

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