octave-maintainers
[Top][All Lists]
Advanced

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

implementing inputParser (request advice for API)


From: Carnë Draug
Subject: implementing inputParser (request advice for API)
Date: Thu, 27 Oct 2011 23:08:59 +0100

Hi

I've been trying to implement MatLab's inputParser utility (it's a
class that helps functions to check validity of input arguments and
makes implementing a param/value scheme quite easy). I'm trying to be
MatLab compatible (I don't need this compatibility, I just thought it
would be nice since I would like to contribute it to the project) but
I have the problem that octave doesn't support object handles to
create it so I would like to know the best way to do this.

>From what I gathered from their online documentation and Ben Abbott
help, Matlab's has the following 2 types of APIs:

p = inputParser;      # construct object
p.addRequired ('a');  # type 1
addRequired (p, 'a'); # type 2

To mimick this behaviour, I can use 'inputname(1)' and then
'assigin('caller', ...)' at the end, but this is a ugly hack that may
fail on some corner cases and jwe is against it. As such, my
implemention currently has the following 2 API:

p = inputParser;          # construct object
p = p.addRequired ('a');  # type 3
p = addRequired (p, 'a'); # type 4

I could try to change the code to support all 4 types of API at the
same time, using the hack in some cases for compatibility only. Or I
could have any mix of them, maybe type 1 and type 4 only?

I'm forwarding the e-mail exchange I had between Ben Abbott and John
Eaton yesterday about this at the end of the e-mail.

Carnë

On 26 October 2011 19:30, Ben Abbott <address@hidden> wrote:
> On Oct 26, 2011, at 2:23 PM, John W. Eaton wrote:
>> On 26-Oct-2011, Ben Abbott wrote:
>> | On Oct 26, 2011, at 1:50 PM, Carnë Draug wrote:
>> | > But maybe it's meant to be used as 'addRequired (p, ...)' and the
>> | > argument is modifed rather than returned.
>> |
>> | I see where MW's creates the object ...
>> |
>> |     p = inputParser;
>> |
>> | But I don't see any other example of "p = ..."
>> |
>> | I also don't see any mention of addRequired(p, ...). That's less of a 
>> problem since you're able to handle that already (I think I can modify my 
>> implementation as well, but haven't tried).
>>
>> I don't think there is any reason you can't use a value class here, if
>> you are willing to always call it with
>>
>>  p = method (p, ...);
>
> Is there a problem with ...
>
>        p = p.method(...)
>
> ... this is slightly more consistent with ML.
>
>> But it won't be compatible with Matlab's inputParser class.  There is
>> just no way to reliably fake handle classes and have them work the way
>> that they do in Matlab.
>>
>> jwe


reply via email to

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