Re: on passing arguments to a function, how to break a list into
- To: mathgroup at smc.vnet.net
- Subject: [mg103740] Re: on passing arguments to a function, how to break a list into
- From: Albert Retey <awnl at gmx-topmail.de>
- Date: Sun, 4 Oct 2009 05:37:06 -0400 (EDT)
- References: <ha7hvj$5qe$1@smc.vnet.net>
Hi,
> Suppose there is a function foo[] which returns back 2 items, say 'i' and
> 'j'. They must be returned as a list ofcourse, so we have this
>
> foo[] := Module[{i, j},
> i = 3;
> j = 7;
> {i, j}
> ]
>
> Now I have another function goo[] which accepts 2 items as input, and does
> something with them, as in
>
> goo[i_, j_] := Module[{},
> i + j
> ]
>
> Now I'd like to call foo[], and take its output, and pass it to directly to
> goo[], but I can NOT do the following:
>
> goo[foo[]]
Everything you need is already there (of course :-)). This will do the
trick:
goo@@foo[]
or
Apply[goo,foo[]]
another thing you might want to look at is Sequence, I use it often in
combination with Apply, e.g. if a function goo3 wants three arguments
you could do something like:
goo3[1,Sequence@@foo[]]
hth,
albert