Re: Picking Arguments
- To: mathgroup at smc.vnet.net
- Subject: [mg74012] Re: Picking Arguments
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Mon, 5 Mar 2007 04:58:18 -0500 (EST)
- Organization: The Open University, Milton Keynes, UK
- References: <esdka9$ou3$1@smc.vnet.net>
Mr Ajit Sen wrote:
> Dear MathGroup,
>
> Given a list of functions
>
> A={f[x],g[p,q,r,s],h[u,v,w]},
>
> I'd like to pick out their arguments as a list.
>
> Cases[A,_[args__]:>{args}]
>
> works fine returning {{x}, {p,q,r,s}, {u,v,w}}.
>
> How do I achieve the same thing with Select ?
Might be difficult and kind of convoluted since Select expects that its
second argument returns a boolean value True or False. (Indeed, any
value returned by the test function that is not explicitly the symbol
True will be deemed as a failure.)
One way to implement your request would be to build a test function that
always returns False to Select (in doing so it prevents Select to build
a list) and with side effect (that is a test function that also
construct a list).
You would be better off by using something else. Here is some examples:
In[1]:=
A = {f[x], g[p, q, r, s], h[u, v, w]};
Cases[A, _[args__] :> {args}]
Cases[A, _[args__] -> {args}]
List@@@A
Apply[List, A, {1}]
Replace[A, _[args__] :> {args}, {1}]
Replace[A, _[args__] -> {args}, {1}]
Out[2]=
{{x}, {p, q, r, s}, {u, v, w}}
Out[3]=
{{x}, {p, q, r, s}, {u, v, w}}
Out[4]=
{{x}, {p, q, r, s}, {u, v, w}}
Out[5]=
{{x}, {p, q, r, s}, {u, v, w}}
Out[6]=
{{x}, {p, q, r, s}, {u, v, w}}
Out[7]=
{{x}, {p, q, r, s}, {u, v, w}}
Regards,
Jean-Marc