Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm interested in the arguments of f in expressions like

f[a]@f[b]@f[c]

By argument I mean what is here a, b and c. I would like to know the arguments and in what order they appear. For example, the order of the arguments in

 f[d]@(2 x f[b])@f[c]@f[q]

is

 {d, b, c, q}

How can I find this from the above expression? I tried to use Level[], but the Subvalue construction is hindering me.

share|improve this question
    
What would be an appropriate title for this question? –  sjdh Sep 20 '12 at 12:01
add comment

2 Answers 2

up vote 3 down vote accepted

Here is another way:

Cases[f[d]@(2 x f[b])@f[c]@f[q], f[x_] :> x, {-2}, Heads -> True]
share|improve this answer
add comment

This works:

expr = f[d]@(2 x f[b])@f[c]@f[q];
Extract[expr, Position[expr, f[_]], First]
   {d, b, c, q}

Note that Extract[] and Position[] are able to handle expressions with any head, not just lists.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.