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 have two Functions, f[] and g[]. f is passed some values ,say {w,x,y,z} and I want to send one of those to g say x. I don't want this operation to interfere with other operations.

share|improve this question
3  
can you be more specific? eg why does g[x_]:=x; f[{w_,x_,y_,z_}]:=g[x] not work? –  acl Dec 19 '12 at 12:31
1  
f[l_]:=(g[First@l]; whatever) –  ssch Dec 19 '12 at 12:33
    
@acl fine i'l tell you the entire problem. –  santhosh Dec 19 '12 at 12:37
    
you don't need to put the entire problem here, just some sort of minimal example –  acl Dec 19 '12 at 12:38
6  
The better you explain your problem to us, the better the chances to get good answers. Your question style so far is kind of short bordering on incomplete. –  Yves Klett Dec 19 '12 at 12:41
show 3 more comments

1 Answer

Is this what you have in mind by any chance? I'm simply using an external variable to store the x passed to f when f is called. The Module is there so that that external variable is only known by f and g and you don't accidentally use it in other places

Module[{var},
 f[{w_, x_, y_, z_}] := (var = x; 8);
 g[] := var
 ]

So now if you run

f[{1, 2, 3, 4}]

you get

(* 8 *)

But next time you run g[] you get the "x argument" passed to f the last time it was called

g[]

(* 2 *)
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.