Define a slightly messy function - in this case a sum of random Gaussians:
Takes no time at all to plot, or evaluate 10^3 times:
Now put the whole thing in a procedure A(z), so that we can use A(z) as a function unless it's called with a numeric argument:
if not zz::numeric then return 'procname'(args) fi;
Now it takes ages and 100's of megs of memory to evaluate! (Note: evaluating 100 not 1000 points):
I have been using this if statement for years with no problems like this, but much exploring leads me to the conclusion that it's that. But why, and how do I fix it? More generally, what's the 'correct' way to write a procedure which evaluates to its name unless all arguments are numeric?
Thanks in advance!