Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Picking Arguments

  • To: mathgroup at
  • Subject: [mg74012] Re: Picking Arguments
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at>
  • Date: Mon, 5 Mar 2007 04:58:18 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <esdka9$ou3$>

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:

A = {f[x], g[p, q, r, s], h[u, v, w]};
Cases[A, _[args__] :> {args}]
Cases[A, _[args__] -> {args}]
Apply[List, A, {1}]
Replace[A, _[args__] :> {args}, {1}]
Replace[A, _[args__] -> {args}, {1}]

{{x}, {p, q, r, s}, {u, v, w}}

{{x}, {p, q, r, s}, {u, v, w}}

{{x}, {p, q, r, s}, {u, v, w}}

{{x}, {p, q, r, s}, {u, v, w}}

{{x}, {p, q, r, s}, {u, v, w}}

{{x}, {p, q, r, s}, {u, v, w}}


  • Prev by Date: Re: Rigid body equations
  • Next by Date: Re: Replacing list elements while retaining structure
  • Previous by thread: Re: Picking Arguments
  • Next by thread: Re: Picking Arguments