# Variable passing

I am having trouble understanding how variables are passed in as parameters.

My goal is to create a function

f(logical,x,y,z) = Evaluate [logical(x,y,z)]


From there I should be able to call f(x||y||z, x,y,z)

and it will output (false||false||false).

My current format:

func1[expr_,xval_,yval_,zval] = expr /. {xval->x, yval ->y, zval ->z}


Obviously this is wrong because I have yet to define x,y,z until I call the function. Really just unsure of the format and have no idea where to go.

• func1 is just ReplaceAll, maybe with Hold or Defer. Try ReplaceAll[Hold[x||y||z],{x->False, y->False, z->False}] or ReplaceAll[Defer[x||y||z],{x->False, y->False, z->False}]. If you want it in function form, just set HoldFirst or HoldAll to the function. – b3m2a1 Sep 13 '17 at 4:07
• Why would f[x || y || z, x, y, z] necessarily return False || False || False? If x, y and z were False, it would automatically evaluate to just False (hence @b3m2a1's comment). If x, y and z did not have truth values it would just return unevaluated x || y || z. – aardvark2012 Sep 13 '17 at 4:57
• Please find a descriptive title for your questions. See the asking guidelines. – Szabolcs Sep 13 '17 at 8:09

I would recommend starting in the wolfram documentation for functions. I'm not completely sure what you are trying to do with your inputs, but I believe you want to make a function that evaluates some other function or functions. You could write this as

func1[expr_, x_, y_, z_] := expr[x, y, z];


then create whatever expressions you need to evaluate

equation1[x_, y_, z_] := x + y + z;
equation2[x_, y_, z_] := x^2 + y^2 + z^2;


then pass them both into func1

func1[#, 1, 2, 3] & /@ {equation1, equation2}


For a logical function it is similar. Lets assume you have defined variables somewhere in your book

x=1;
y=2;
z=3;


then

equation3[a_, b_, c_] := x == a || y == b || z == c;


will check if the inputs a, b, or c are equal to x, y, or z, respectively. So

func1[eq3, 1, 23, 45]


will give you True, since a (1) is equal to x. Finally, to output some array, just make the equation an array:

equation4[a_, b_, c_] := {TrueQ[x == a], TrueQ[y == b], TrueQ[z == c]}


then

func1[equation4, 1, 2, 3]


returns

{True, False, False}

• func1[Or, x, y, z] (returns x || y || z) might clarify things for the OP. Also, func1 is essentially Apply. – aardvark2012 Sep 13 '17 at 5:02