[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: OO in octave.
From: |
Carnë Draug |
Subject: |
Re: OO in octave. |
Date: |
Mon, 4 Feb 2013 23:09:26 +0000 |
On 4 February 2013 22:53, ernst <address@hidden> wrote:
>> On 4 February 2013 20:42, ernst <address@hidden> wrote:
>>> Hi Carnė,
>>>> On 31 January 2013 12:26, <address@hidden> wrote:
>>>>> Date: Thu, 31 Jan 2013 00:09:17 +0100
>>>>> From: ernst <address@hidden>
>>>>> To: address@hidden
>>>>> Subject: OO in octave.
>>>>> Message-ID: <address@hidden>
>>>>> Content-Type: text/plain; charset=ISO-8859-1
>>>>>
>>>>> Hi all,
>>>>> i know OO from java: x.function(a,....) means function(x,a,...)
>>>>> where the class of x determines the choice of the function.
>>>>>
>>>>> For octave i did not find an according statement in the docu.
>>>>> Does octave rely on the 1st argument only, as java does or does it look
>>>>> after all?
>>>> You can have both ways with Octave. Look at the inputParser class in
>>>> the general package for an example. Basically you'll need to play with
>>>> subsasgn and subsref.
>>> thank you for your answer.
>>> I found the general package but did not find the inputParser class.
>>> Maybe the problem is the version? I use 3.6.2.
>>> I searched all the loadpath. No success.
>> The general package has the inputParser class since version 1.3.0. The
>> current version is 1.3.2. Download the tarball here
>>
>> http://octave.sourceforge.net/general/index.html
>>
>> and look inside the inst/@inputParser directory.
>>
>>> What I did is, to have a look at the documentation.
>>> I suspect that somewhere in my brain there is a deep misconception about
>>> OO in octave.
>>>
>>> I always thought, that subasgn and subsref refer to aspects of a single
>>> object,
>>> typically of its components,
>>> whereas i am talking about a list of parameters possibly consisting of
>>> many objects.
>>> Or does octave not distinguish between
>>> function (a,b,c) (3 elements) and function([a b c]) which is one only?
>> Basically you can can configure how indexing the object works. You can
>> use "()", "{}" or "." like you would for matrices, cells and
>> structures. Instead of using the dot for accessing a structure field,
>> you can use it to run methods. So you end up with the following syntax
>>
>> obj.method (args)
>>
>> It's not very complicated, look into the source of inputParser and we
>> might help you when you have specific questions.
>>
>> Carnė
>>
> Hi Carnė,
> i think now i understood: you talked about: how to realize NOTATION
>
> obj.method (args)
>
> as an alternative to method(obj, args).
>
> Great! and tricky. Tanks.
>
> but: What i originally wanted to know, is the lookup mechanism for choosing
> 'method'.
> Is it as follows?:
>
> if method(obj, args) is found and obj is a class object of class cls,
> search for file method.m in folder @cls and apply the function in method,m.
> True?
>
> Or are the classes of the other arguments also taken into account when
> looking up the method?
>
> greetings,
>
> Ernst
Yes, I was explaining how to write the alternative notation.
Apologies, I misunderstood your question.
See the answer Julien Bect gave [1] then. The note at the bottom of
the manual that he links to says that user classes have higher
precedence that Octave's built-in classes. It's undocumented what
happens when there's two classes with the same precedence. In that
situation, I think it looks for the object on the left.
Carnë
[1] http://octave.1599824.n4.nabble.com/OO-in-octave-tp4649299p4649322.html