MathGroup Archive 2005

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

Search the Archive

"meta-programming" ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60908] "meta-programming" ?
  • From: Jack Goldberg <jackgoldberg at comcast.net>
  • Date: Mon, 3 Oct 2005 04:06:06 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

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


  • Prev by Date: Re: Re: Bug in Mathematica ?
  • Next by Date: Re: How to "search" in a matrix?
  • Previous by thread: Opinions?:Foundations of Fluid Mechanics with Applications
  • Next by thread: Re: "meta-programming" ?