MathGroup Archive 1998

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

Search the Archive

Re: Computing dynamic functions



In a private response to my earlier posting Gabriel Alvarez writes

> What I do not know how to do is to type
>
> ``Something with h's, x_, := ...  and Expand[(1+x)^2]''
>
> and get
>
> h[x_]:= h[x] = 1 + 2 x + x^2

The following does this

In[1]:=
remember[ h_,x_,g_]:= (h[x_]:=h[x] = g)

RuleDelayed::"rhs": 
    "Pattern \!\(x_\) appears on the right-hand side of rule \
\!\(\(remember[\(h_, x_, g_\)]\) \\[RuleDelayed] \(\(h[x_]\) :=
\(\(h[x]\) = \ g\)\)\)."

We can ignore the message.

In[2]:=
remember[h,x,Expand[(1+x)^2]]

In[3]:=
?h

"Global`h"

h[x_] := h[x] = 1 + 2*x + x^2

Some use of holding attributes would change the behaviour

-- 
Allan Hayes
Training and Consulting
Leicester, UK
hay@haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642



  • Prev by Date: Bug in summing series
  • Next by Date: Calculus`FourierTransform`
  • Prev by thread: Re:Computing dynamic functions
  • Next by thread: editing problems