help-octave
[Top][All Lists]
Advanced

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

Re: named arguments


From: Jordi Gutiérrez Hermoso
Subject: Re: named arguments
Date: Fri, 16 Mar 2012 08:43:35 -0400

2012/3/16 Jordi Gutiérrez Hermoso <address@hidden>:
> On 16 March 2012 07:53, Olaf Till <address@hidden> wrote:
>> I'm not aware of Octave supporting named arguments. There was once a
>> suggestion to support named arguments, but it has been disapproved
>> because of the risk of future incompatibilities with Matlab.
>
> I wish we could fix this. Named arguments are a huge convenience. Can
> you think of something better than this?
>
>    http://abandonmatlab.wordpress.com/2009/07/31/no-named-arguments/

Oh, and here is my idea:

Introduce some sort of syntax in function declarations (maybe
something like Python's traditional **kwarg?) that will give you a
struct with the named arguments, so perhaps something like

    function out = foo(bar, baz, **kwarg)
        ## ...
    endfunction

Now if you call the function like this:

    foo(1,2 "oh", 2, "hai", rand(3), "there", "lol");

then in the body of the function, kwarg will be a struct that contains
the fields oh, hai, there, with the corresponding values 2, rand(3),
and "lol".

This idea probably breaks Matlab compatibility in subtle ways, right?
I consider "Matlab compatibility" to be "if it works in Matlab, it
should work in Octave", i.e. the set of valid Matlab scripts should be
a subset of the set of valid Octave scripts. Would this work?

- Jordi G. H.


reply via email to

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