dynamic programming inside a function
- To: mathgroup at smc.vnet.net
- Subject: [mg40409] dynamic programming inside a function
- From: Ken Sale <kesale at llnl.gov>
- Date: Fri, 4 Apr 2003 01:23:37 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Hi MathGroup,
I'm trying to figure out how to create a function that remembers its
values inside a function definition (I want the temporary function to
stay hidden in a package eventually. I've tried the following
test[f_, vars_List] :=
Module[{v, vPat},
Clear[temp];
vPat = Sequence @@ (Pattern[#, Blank[]] & /@ vars);
v = Sequence @@ vars;
temp[vPat] := temp[v] = f[v];
]
When I evaluate
test[Sin, {x}]
I find that the definition of temp isn't what I want
?temp
temp[x_] := temp[v$97] = Sin[v$97]
What I'd like to get instead is
temp[x_] := temp[x] = Sin[x]
I've tried putting ReleaseHold around various parts of the assignment
but so far haven't found a way to do what I want.
Any help will be appreciated.
Thanks,
Ken
--
Ken Sale
Group Leader / Physicist
Radiation Technology Group
Lawrence Livermore National Laboratory
(925) 423-0686
- Follow-Ups:
- Re: dynamic programming inside a function
- From: Dr Bob <majort@cox-internet.com>
- Re: dynamic programming inside a function