[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Classdef embryonic support
From: |
Ben Abbott |
Subject: |
Re: Classdef embryonic support |
Date: |
Sat, 12 Jan 2013 11:34:11 -0500 |
On Jan 6, 2013, at 10:35 PM, Michael Goffioul wrote:
> On Tue, Jan 1, 2013 at 8:09 PM, Michael Goffioul <address@hidden> wrote:
> Hi,
>
> Just a heads up to let people know I've spent some time during my christmas
> holiday to start working again on the classdef branch. I've just pushed some
> changes to implement initial support for handle-class and value-class
> semantic. Don't expect too much out of it, but maybe some of you are
> interested in giving it a try. For instance, I'd be more than happy if
> someone would write unit tests for the classdef support.
>
> Did anybody have a chance to give it a try? Although far from finished, it's
> already somehow usable (you can define classes, methods, properties, use
> inheritance and make superclass calls; it also supports handle and value
> semantics).
>
> Michael.
The classef branch now builds on MacOS X! :-)
I'm new to classdef, so I borrowed an example from the Mathworks site, made
some modifications, and added some tests (see the attached payment.m)
However, I'm not sure how to go about adding tests to the sources. Perhaps
syntax like below be added to the test feature?
%!classdef payment
%! properties
%! rate;
%! term;
%! principle;
%! end
%! methods
%! function obj = payment (r, t, p)
%! obj.rate = r;
%! obj.term = t;
%! obj.principle = p;
%! end
%! function amt = amount (obj)
%! i = obj.rate / (12 * 100);
%! amt = (obj.principle * i) / (1 - (1 + i)^(-obj.term));
%! end
%! end
%!endclassdef
For now, tests can be added to a classdef m-file, but I don't see how that
would be committed.
In any event, the current implementation allows methods to be called as
obj.method(arg1,arg2, ...), but not as method (obj, arg1, arg2, ...).
Also Matlab has three universal (?) methods, "properties", "methods", "events".
properties(obj): Returns a column oriented cellstring array of the
public properties for the object.
methods(obj): Returns a column oriented cellstring array of the public
methods for the object.
events(obj): Returns a column oriented cellstring array of the public
events for the object.
For example ...
methods ('char')
Methods for class char:
abs evalc isnan mrdivide
real sum
all evalin issorted mtimes
regexp superiorfloat
and exist javaArray ne
regexpi times
anonymousFunction fftw java_array newdepfun
regexprep transpose
any find ldivide nnz
regexptranslate tril
bsxfun fix le nonzeros rem
triu
ceil floor linsolve not
reshape uminus
colon full lt nzmax
round unicode2native
conj ge max or
sign uplus
ctranspose gt min permute
sort xlate
diag hregister minus plus
sortrowsc xor
display imag mldivide power
sparse
eq isfinite mod prod
sparsfun
eval isinf mpower rdivide
str2func
There is no core function for properties() or events() for Octave, but there is
a methods.m function.
methods ('char')
error: [java] java.lang.ClassNotFoundException: char
error: called from:
error:
/Users/bpabbott/Development/mercurial/classdef/sources/scripts/general/methods.m
at line 45, column 16
I don't know if there are any serious compatibility concerns, but I thought
I'd mention what I found while tinkering with classdef.
Ben
payment.m
Description: Binary data