help-octave
[Top][All Lists]
Advanced

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

## Multi-return functions as arguments

 From: Ted Harding Subject: Multi-return functions as arguments Date: Fri, 18 Sep 1998 16:11:04 +0100 (BST)

```Folks, I'm trying to get my head clear -- and also implement a routine --
about the use of functions returning multiple values as arguments to
another (wrapper) function. How can the wrapper function determine the
number of values returned by its argument?

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. I _could_ of
course simply write this as

[x1,x2] = F2(u); y = G(x1,x2);
or
[x1,x2,x3] = F3(u); y = G(x1,x2,x3);

but I would like the former more flexible approach -- the real point
being that I want to be able to cover the case where the internals of G
define the number of its returned values, depending on the value of (u),
(e.g. using vr_val) so this may not be explicitly available when the
program is being written.

Again, this can be done "bare hands" by making the first output argument
tell the number of remaining values, but I would prefer to avoid handling
it so explicitly: the "y = G(F2(u))" and "y = G(F3(u))" would be so much
more flexible). Another approach, I suppose, would be to return a
structure; but this would be a sledgehammer for a nut if the simpler
approach was possible.

Any advice, suggestions or info much appreciated.

With thanks,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <address@hidden>
Date: 18-Sep-98                                       Time: 16:11:04
--------------------------------------------------------------------

```

reply via email to

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