octave-maintainers
[Top][All Lists]
Advanced

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

Re: `argn' ? … still part of Octave?


From: Carnë Draug
Subject: Re: `argn' ? … still part of Octave?
Date: Tue, 25 Oct 2011 10:05:38 +0100

On 24 October 2011 19:41, Ben Abbott <address@hidden> wrote:
> On Oct 24, 2011, at 10:12 AM, Carnë Draug wrote:
>
>> On 24 October 2011 13:23, Ben Abbott <address@hidden> wrote:
>>> On Oct 24, 2011, at 6:09 AM, Carnë Draug wrote:
>>>
>>>> On 23 October 2011 19:21, Ben Abbott <address@hidden> wrote:
>>>>> On Oct 5, 2011, at 9:31 PM, Carnë Draug wrote:
>>>>>
>>>>>> On 6 October 2011 01:27, John W. Eaton <address@hidden> wrote:
>>>>>>> | idea is to use arg (or inputname) to get the name of the variable in
>>>>>>> | the caller and change its value with assignin('caller',...)
>>>>>>>
>>>>>>> OK, I guess you can try that, but it will be somewhat slow and
>>>>>>> it seems to me that it will definitely be clumsy.
>>>>>>
>>>>>> I know. But the class I'm trying to implement (inputParser) already
>>>>>> exists in MatLab. It's for the sake of compatibility. And I'm learning
>>>>>> something new in the process too :)
>>>>>>
>>>>>> Carnë
>>>>>
>>>>> Carnë,
>>>>>
>>>>> Any progress on implementing a compliant inputParser?
>>>>>
>>>>> I had contacted Nico Schlomer and cooperated with him to modify his 
>>>>> matlab2tikz to allow it to run on Octave. He had made good use of 
>>>>> Matlab's inputParser. The replacement used by matlab2tikz contains much 
>>>>> of the same functionality.
>>>>>
>>>>>        http://win.ua.ac.be/~nschloe/content/matlab2tikz
>>>>>
>>>>> You may find some code there that is helpful toward your effort (Take a 
>>>>> look at matlab2tikzInputParser.m)
>>>>
>>>> Hi Ben,
>>>>
>>>> yes. I finished it some days ago but I still need to write the
>>>> documentation and would like to test it a bit more before submitting
>>>> it ( https://gitorious.org/octave-devel/inputparser ). I do not have
>>>> matlab to test how compliant it is, I've just been following what they
>>>> have written on the inputParser documentation. Hopefully it'll be
>>>> ready sometime during next weekend.
>>>>
>>>> But thank you for the link. I looked on the way he did it and found it
>>>> very interesting how he mimicked an object by creating a struct with
>>>> fields that are simply function handles for functions that were only
>>>> in scope when the struct was created.
>>>>
>>>> Carnë
>>>
>>> The parser code now used by matalbtikz is mostly mine. I has originally 
>>> tried to do what you are working on. My original code with the 
>>> "@inputParser" directory is attached.
>>>
>>> There is a simple example from the ML docs below.
>>>
>>>       p = inputParser;
>>>
>>>       p.addRequired('a');
>>>       p.addOptional('b',1);
>>>       p.addParamValue('c',2);
>>>
>>>       p.parse(10, 20, 'c', 30);
>>>       res = p.Results
>>>
>>>       res =
>>>          a: 10
>>>          b: 20
>>>          c: 30
>>>
>>> I was unable to fake the self modifying methods (I'll take a look at how 
>>> you did that later today). Instead, my implementation works as ...
>>>
>>>       p = inputParser;
>>>
>>>       p = p.addRequired(p, 'a');
>>>       p = p.addOptional(p, 'b',1);
>>>       p = p.addParamValue(p, 'c',2);
>>>
>>>       p = p.parse(p, 10, 20, 'c', 30);
>>>       res = p.Results
>>>
>>>       res =
>>>          a: 10
>>>          b: 20
>>>          c: 30
>>
>> Mine is working the same, it's nice to know the parsing seems
>> compatible (I used this function http://pastebin.com/AyvqMX12 to test
>> it that I got from the documentation online). I did manage an ugly
>> kludge to mimic the self modifying API but discussing it with jwe on
>> #octave, he didn't like it and he was right. For example, if the
>> object was stored inside a structure, my hack would actually replace
>> the whole structure. So in the end, I never applied it. It's commented
>> out on the code (pretty much all the class code is in subsref)
>>
>>  ## the following at the end may allow to use the obj.method notation one day
>>  ## jwe is very against this ugly hack
>>  ## what would happen if the user has the obj inside a struct? Bad things!
>> #  ori = inputname(1);
>> #  assignin('caller', ori, inPar);
>>
>> But matlab also has a p = addRequired (p, ...) type of API. My code
>> should also work fine if used that way so it should be possible to
>> write code that is 100% compatible.
>>
>> octave:1> p = inputParser;
>> octave:2> p = addRequired(p, 'a');
>> octave:3> p = addOptional(p, 'b',1);
>> octave:4> p = addParamValue(p, 'c',2);
>> octave:5> p = parse(p, 10, 20, 'c', 30);
>> octave:6> res = p.Results
>> res =
>>
>>  scalar structure containing the fields:
>>
>>    a =  10
>>    b =  20
>>    c =  30
>>
>>
>> I won't have much time the next days and going to Dublin tomorrow, but
>> will look at it again on Thursday. I noticed that you also implemented
>> comparison operators for the class. Is that your "expansion" of the
>> class, or is it for compatibility with Matlab?
>>
>> Carnë
>
> Its been several months since I worked on this, so some skepticism of my 
> recollection is merited. However, I recall I intended my implementation is 
> consistent with Matlab.

Ok. I do not have, and never had, access to MatLab so all I know is
from their online documentation. What happens when you use arithmetic
or boolean operators on the objects is not something they had
documented. When I'm back to the lab I'll add them.

> One point that I'm unsure about is your implementation of addRequired (and 
> the other methods). I tried "help addRequired", but encountered an error.
>
>        help addRequired
>
>        addRequired not found.

For the help text, you'll need 'help @inputParser/addRequired'

> I also encountered an error with calling the function ...
>
>        p = inputParser;
>        p = AddRequired (p, 'a')
>        Undefined function 'AddRequired' for input arguments of type 
> 'inputParser'.

The first 'a' in 'AddRequired' should be lowercase.

> I thought I'd try the syntax I used, but did no better.
>
>        p = p.AddRequired (p, 'a')
>        No appropriate method, property, or field AddRequired for class 
> inputParser.
>
> I'm running Matlab R2011b. Perhaps the API you mention has been deprecated?

Again, the first character should be lowercase. Or maybe it is
deprecated. As I saied before, I only have their online docs which say
these two are valid:

p.addRequired(argname, validator)
addRequired(p, argname, validator)

Carnë


reply via email to

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