MathGroup Archive 2006

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

Search the Archive

Re: delayed rule evaluation order

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68015] Re: [mg67967] delayed rule evaluation order
  • From: "Chris Chiasson" <chris at chiasson.name>
  • Date: Thu, 20 Jul 2006 06:04:55 -0400 (EDT)
  • References: <200607190921.FAA21363@smc.vnet.net> <44BE2B26.70206@wolfram.com>
  • Sender: owner-wri-mathgroup at wolfram.com

This is a fairly interesting replacement technique; it reminds me of
the one David Park used for capturing side-effects of Condition
processing.

http://forums.wolfram.com/mathgroup/archive/2006/May/msg00621.html

Unfortunately, it is causing unwanted evaluations. Why does it do this?

In[1]:=
f[1]=1;
f[n_Integer]=n f[n-1];
f[2`3]
z=Trace[f[2]]
z/.{blah_?ExactNumberQ\[RuleDelayed]With[{p=SetPrecision[blah,3]},p/;True]}

Out[3]=
f[2.00]

Out[4]=
{f[2],2 f[-1+2],{{-1+2,1},f[1],1},2 1,2}

Out[5]=
{2.00,2.00,{{1.00,1.00},1.00,1.00},2.00,2.00}

The output is humorous (in a demented way, I guess) if With is
replaced with Module.

Thanks,

On 7/19/06, Carl K. Woll <carlw at wolfram.com> wrote:
> Chris Chiasson wrote:
> > Hold[{2, 3}] /. {{x_, y_} :> x^y}
> >
> > the result is Hold[Power[2,3]]
> >
> > I would like the result to be Hold[8]
> >
> > The original context is post-processing of a large Trace output (via
> > SetPrecision to get rid of digits and improve readability).
> >
> > Any ideas?
> >
>
> This is not an easy one to figure out. One possibility is given in the
> help for ReplaceAll in the last example of the Further Examples section.
> In this example the following construct is used:
>
> In[27]:= Hold[{2, 3}] /. {x_, y_} :> With[{p = x^y}, p /; True]
>
> Out[27]= Hold[8]
>
> Carl Woll
> Wolfram Research
>


-- 
http://chris.chiasson.name/


  • Prev by Date: Re: Norm
  • Next by Date: Re: Efficient compounding of growth figures
  • Previous by thread: Re: delayed rule evaluation order
  • Next by thread: Re: delayed rule evaluation order