Re: "meta-programming" ?

*To*: mathgroup at smc.vnet.net*Subject*: [mg60928] Re: [mg60908] "meta-programming" ?*From*: "Christoph Lhotka" <lhotka at astro.univie.ac.at>*Date*: Tue, 4 Oct 2005 01:24:56 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

On Mon, 3 Oct 2005 04:06:06 -0400 (EDT) Jack Goldberg <jackgoldberg at comcast.net> wrote: > Hello once again, > > I tend to use a lot of Modules in my programming style. Here is a > model example: > > myfunction[ ] := Module[ {L1, L2, L3}, > L1 = some computations; > L2 = more computations; > L3 = more computations; > final touches > ] > > When it comes time to check special (extreme) cases I use the simple > scheme of sequencially commenting out lines to see what has > happened. In the next example I comment out lines L3 to LN (here > L3 is the last labeled line). > > myfunction[ f__ ] := Module[ {L1, L2, L3}, > L1 = some computations; > L2 = more computations (*; > L3 = more computations; > final touches *) > ] > > If the output is what I expect, I comment out L3, etc. So, in > short, if there are 10 lines of code in my module, I start with line > L1 and proceed to L10. When every line does as expected, I try the > function on still another special case. > > Now my question. Can a "meta" program be constructed which does this > automatically? Specifically, this metaprogram takes the input is > myfunction and a specific input f to myfunction. The metaprogram > returns the output of each line of the module evaluated for the > specific input f to myfunction thus saving me the bother of > commenting out each line, one at a time for each extreme input to > myfunction. (An extreme input might be an empty sum or a sum with > just one term, to take two easy examples. Of course, this kind of > thing happens when myfunction is deeply embedded in other code.) > > Obviously, I am reluctant to use Trace or any of its variations. But > perhaps some version of Trace is the way to go. Well, at the very > least I can stick to the old fashion way, "one line at a time". > > Jack > My solution to this problem was to define a global debug variable $D and to define my function like this: function[args__]:=Module[{vars}, $D={ command1, command2, ... }[[-1]] ] so I was able to see what happens inside the function by accessing $D. In[..]:=$D hope it helps -- Mag. Christoph Lhotka -- University of Vienna / Institute for Astronomy mail. lhotka at astro.univie.ac.at