MathGroup Archive 2010

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

Search the Archive

Re: pure function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113757] Re: pure function
  • From: Vince Virgilio <blueschi at gmail.com>
  • Date: Wed, 10 Nov 2010 06:30:57 -0500 (EST)
  • References: <ib8cre$2e1$1@smc.vnet.net>

On Nov 8, 3:37 am, Stephan <stschiff80 at googlemail.com> wrote:
> 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 a=
ctual _value_ of the local variable a, instead of the _symbol_ ?
>
> So I would like the returned function to be written as
>
>         Function[{x$}, 2 x$]
>
> The reason is, that I would like to have a quick way to actually see the =
value instead of digging out the local variable a$57...
>
> Thanks,
>
> Stephan

Or use ReplaceAll instead of With:

getFunc := Module[{a = 2}, Function[{x}, a*x] /. HoldPattern@a ->
a ] ;

(Sometimes the postfix notation reads better.)

Vince


  • Prev by Date: Address to the Mathematica-users Wiki Homepage
  • Next by Date: Set::pspec error in parallelized loop in Unix
  • Previous by thread: Re: pure function
  • Next by thread: Re: pure function