help-octave
[Top][All Lists]

## RE: Multi-return functions as arguments

 From: Ted Harding Subject: RE: Multi-return functions as arguments Date: Fri, 18 Sep 1998 18:59:19 +0100 (BST)

```On 18-Sep-98 John W. Eaton wrote:
> On 18-Sep-1998, (Ted Harding) <address@hidden> wrote:
>| As a simple example, suppose I have functions
>|
>|   function [x1,x2] = F2(u) ...
>|   function [x1,x2,x3] = F3(u) ...
>|
>| and I want to write a single wrapper function G, to be called either
>| as
>|
>|   y = G(F2(u))   intended to be equivalent to y = G(x1,x2)
>|
>| or as
>|
>|   y = G(F3(u))   intended to be equivalent to y = G(x1,x2,x3)
>|
>| where what should happen inside G depends on its nargin.
>
> But in either of the two cases above, nargin for G will be 1.
>
> It seems that what you really want to do is have F2 and F3 return
> lists, and then have G accept a list argument and do different things
> depending on the length of the list.

Yes, essentially that's exactly it.

> Unfortunately, there is no list data type in Octave 2.0.x, but there
> will be one in the next major release (it is currently available in
> the 2.1.x development releases).

Thanks for the info -- looking forward to the next release!

Meanwhile (though I guess from the above the answer is probably "no")
is there any variant of "y=G(F3(u))" whereby G can access all three of
the values returned by F3, instead of just the "top" one, i.e. x1?

(The only way I can think of is to use "F3" as argument and use "eval"
inside G: y = G("F3",u) -- better than nothing, but with a tendency to be
slow. Even then, it's not obvious how to get at the returned values
inside G.)

With my thanks,
Ted.

--------------------------------------------------------------------