Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know how to create a function from concrete expression like

Function[{x, y}, x^2 + y^2]

But what if I have a list of expressions list1 and I know the set of variables which can occur in this list. I want to map all expressions of list1 to curresponding functions from these variables. Like

{x^2 + y^2, z^2, x, y}

should be mapped to

  Function[{x,y,z}, x^2 + y^2], 
  Function[{x,y,z}, z^2], 
  Function[{x,y,z}, x], 
  Function[{x,y,z}, y]

I've tried

Function[{x,y,z}, #] &/@ list1

but this doesn't work. Can someone help me with solution?

share|improve this question
Something like g = Function[{x, y, z}, #] & /@ l1; g[[1]][a, b, c]? – Dr. belisarius May 18 '14 at 13:21
Or this way?g = Function[{x, y, z}, #] &@l1; g[a, b, c][[1]] – Dr. belisarius May 18 '14 at 13:22
up vote 2 down vote accepted

One way to do it is:

exprs = {x^2 + y^2, z^2, x, y};
Replace[Function[{x, y, z}, body], {Rule[body, #]} & /@ exprs, {-1}]
   Function[{x, y, z}, x^2 + y^2], 
   Function[{x, y, z}, z^2], 
   Function[{x, y, z}, x], 
   Function[{x, y, z}, y]
share|improve this answer
Thank you, it works! – Artem Malykh May 18 '14 at 20:06

Your Answer


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.