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: Ben Abbott
Subject: Re: `argn' ? … still part of Octave ?
Date: Tue, 25 Oct 2011 07:56:17 -0400

On Oct 25, 2011, at 5:05 AM, Carnë Draug wrote:

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

<snip>

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

My memory is really bad. I don't recall the boolean stuff at all, but they are 
part of ML. Running R2011b ...

        p = inputParser

        p = 

        Input Parser object with:
        CaseSensitive: false
        StructExpand : true
        KeepUnmatched: false
        FunctionName : ''

        p == p

        ans =

             1

        p1 = inputParser

        p1 = 

        Input Parser object with:
        CaseSensitive: false
        StructExpand : true
        KeepUnmatched: false
        FunctionName : ''

        p.FunctionName = 'foo';
        p == p1

        ans =

             0

        p > p1

        ans =

             1

        p < p1

        ans =

             0

>> 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 didn't recall that ML supported  the form "p = addRequired (p, ...): so I 
tried the help function in R2011b.

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

ok. In ML again with the lower case ...

        p = inputParser;
        p = addRequired (p, 'a')

        p =

             []

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

Again in ML R2011b

        p = inputParser;
        p = p.addRequired (p, 'a')
        Error using inputParser/addRequired
        First argument must be a string that can represent a field name.

        p = inputParser;
        p = p.addRequired ('a')

        p =

             []

I don't think ML is doing this by design. It looks like this syntax just isn't 
intended and the empty is an artifact of their implementation. 

What does work in ML R2011b is ...

        p.addRequired ('a')

What I am looking for was confirmation of "matlab also has a p = addRequired 
(p, ...) type of API", maybe I misunderstood you intended to communicate?

In any event, I pulled your implementation, and ran some tests. What certainly 
does work is the documented ML syntax. Nice! I'll have to study what you did. I 
spent a week trying to find a kludge for that last year and eventually gave up.

Ben





reply via email to

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