help-octave
[Top][All Lists]
Advanced

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

Re: named arguments


From: Olaf Till
Subject: Re: named arguments
Date: Fri, 16 Mar 2012 14:36:53 +0100
User-agent: Mutt/1.5.20 (2009-06-14)

On Fri, Mar 16, 2012 at 08:43:35AM -0400, Jordi Gutiérrez Hermoso wrote:
> 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");

If I remember the previous thread right, jwe pointed out that the
problem is with possible future changes in Matlab syntax, i.e. if
Matlab will someday use the syntax you propose for something different
than named arguments, then Octave can't be made compatible to it,
except if it changes its own syntax to handle named arguments.

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

-- 
public key id EAFE0591, e.g. on x-hkp://pool.sks-keyservers.net

Attachment: signature.asc
Description: Digital signature


reply via email to

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