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.

  • 3
    $\begingroup$ can you be more specific? eg why does g[x_]:=x; f[{w_,x_,y_,z_}]:=g[x] not work? $\endgroup$ – acl Dec 19 '12 at 12:31
  • 1
    $\begingroup$ f[l_]:=(g[First@l]; whatever) $\endgroup$ – ssch Dec 19 '12 at 12:33
  • $\begingroup$ @acl fine i'l tell you the entire problem. $\endgroup$ – santhosh Dec 19 '12 at 12:37
  • $\begingroup$ you don't need to put the entire problem here, just some sort of minimal example $\endgroup$ – acl Dec 19 '12 at 12:38
  • 7
    $\begingroup$ 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. $\endgroup$ – Yves Klett Dec 19 '12 at 12:41

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

 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


(* 2 *)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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