MathGroup Archive 2010

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

Search the Archive

Re: pure function

  • To: mathgroup at
  • Subject: [mg113717] Re: pure function
  • From: Albert Retey <awnl at>
  • Date: Mon, 8 Nov 2010 05:40:50 -0500 (EST)
  • References: <ib8cre$2e1$>

Am 08.11.2010 09:37, schrieb Stephan:
> Hi,
> I have a function that returns a pure function:
> In[1]:= getFunc := Module[{a=2}, Function[{x}, a * x]]
> In[2]:= f = getFunc
> Out[2]= Function[{x$}, a$57 x$]
> Is there any way, to have the body of the returned function contain
> the actual _value_ of the local variable a, instead of the _symbol_
> ?

Use With instead of Module:

getFunc := With[{a=2}, Function[{x}, a * x]]

See the documentation of With for some more details and explanations,
and note that Function has attribute HoldAll. You might want to look at
tutorial/NonStandardEvaluation, too.



  • Prev by Date: Re: DownValues
  • Next by Date: Re: pure function
  • Previous by thread: Re: pure function
  • Next by thread: Re: pure function