Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Best practice passing expressions to functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg85305] Re: Best practice passing expressions to functions
  • From: dh <dh at metrohm.ch>
  • Date: Tue, 5 Feb 2008 19:41:37 -0500 (EST)
  • References: <fo9gvu$t1l$1@smc.vnet.net>


Hi Remo,

there is already such a function: Function[var, expr]

where var is the variable in expression.

Note that Function does not evaluate its arguments. E.g. if expression 

is stored in a variable a, you would have to say: Function[var,Evaluate[a]]

hope this helps, Daniel



Remo Aschwanden wrote:

> Hi

> 

> I want to write procedures that accept expressions as parameters and be 

> able define functions based on these expressions, i.e.

> 

> f[exp_]:=Module[

>    "g[x_] := exp "

> ]

> 

> The code between the " " should clarify what I intend to do. Calling 

>    f[x^2-2x+4] 

> should lead to the definition of a function (or pattern)

>    g[x_]:=x^2-2x+4;

> 

> What's the best way to do this? How can I do this without being 

> dependent on the variables used in the expressions ("x")?

> 

> Thank you.

> Remo A.

> 

> 




  • Prev by Date: How does Position work?
  • Next by Date: Re: Best practice passing expressions to functions
  • Previous by thread: Best practice passing expressions to functions
  • Next by thread: Re: Best practice passing expressions to functions