Say I have a function



{4 x, 4 y, 4 z}

Now, let us assign some values to x,y,z

x=7 y=7 z=8

And then we evaluate our function again


{28, 28, 32}

How can I make it so that despite some values being assigned to the variables x,y,z the output of the function Example is only affected by its argument n? I have tried to use SetAttributes[Example,Protected] but that does not work. Could someone help?

  • $\begingroup$ Can you provide more details of why you want to do this? I think you oversimplified your actual issue. $\endgroup$ – Carl Woll May 28 '19 at 21:13
  • $\begingroup$ @CarlWoll I produce a list of symbolic expression, for instance {-x,-y,x,y,x+y,y+z.} $\endgroup$ – amator2357 May 28 '19 at 21:17
  • 1
    $\begingroup$ So, something like: Example[n_Integer]:=(Clear[x,y,z]; n{x,y,z}) will work for you? $\endgroup$ – Carl Woll May 28 '19 at 21:20
  • $\begingroup$ @CarlWoll I produce a list of symbolic expressions, for instance l = {-x,-y,x,y,x+y,y+z}. I then write a function that assigns some expression to x and y, for example x={1,-1,0},y={0,1,-1} so then automatically the remaining symbols in l get assigned a value. Then I want to find a reflection of one of the expression in l in the hyperplane perpendicular to, say x. Once I do that, I'd get, for example, {-1,1,0}. Now, I want to know to which symbol in my initial l that value corresponds, if that makes sense. $\endgroup$ – amator2357 May 28 '19 at 21:25
  • 2
    $\begingroup$ This sounds very much like an XY problem. Can you maybe update your question to reflect what you are truly after? $\endgroup$ – Roman May 28 '19 at 21:45

Just avoid setting x and y.

For example:

f2[l_, n_] := n l;

Clear[x, y, z]
masterl = {x, y, z};

Then you can substitute in values if you want:

xx = 3; yy = 4;
l2 = masterl /. {x -> xx, y -> yy}

(* {3, 4, z} *)

Or do some work with the original list:

f2[masterl, 5]

(* {5 x, 5 y, 5 z} *)

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.