[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Multiple values from a function?
In article <3961EFA8.49657FB6@mathstat.dal.ca>, Simon de Vet <email@example.com> writes:
>I have a function that does a whole lot (it started out as an
>independent program). It works very well when returning one of it's
>It also produces a number of other arrays which I'd like to have access
>to. Unfortunately, I have discovered that a function can only return
>How can I get the other arrays out of it? The code is intertwined, so it
>would be hard to break into 2 or 3 independent functions.
You can easily return them using keyword parameters. Lets say that
your function FUN calculates 3 arrays (internally known as XARR, YARR
and ZARR) and returns XARR. Then, modify the definition of the
function to something like
Fuction FUN, ... ..., second = yarr, third = zarr
Now, if you'll issue a call like
u = Fun( .... ,second = v, third = w)
then after the call U will contain the calculated XARR, V will contain
YARR, w will contain ZARR. This can be extended indefinitely. Note
that neither U not V or W need to be defined at all, prior to the
Mati Meron | "When you argue with a fool,
firstname.lastname@example.org | chances are he is doing just the same"