Question: Question about CodeGeneration

I'm trying to use the CodeGeneration package to generate code for a series expansion. I'd like to wrap it in a function that specifies the arguments, so that the code generation package can generate a complete function definition along with definitions for all the temporary variables.

with(CodeGeneration):
f := proc(r): x->r end proc:
to_translate := f(convert(series(sin(x),x,20),polynom));

to_translate := proc (x) options operator, arrow; x-(1/6)*x^3+(1/120)*x^5-(1/5040)*x^7+(1/362880)*x^9-(1/39916800)*x^11+(1/6227020800)*x^13-(1/1307674368000)*x^15+(1/355687428096000)*x^17-(1/121645100408832000)*x^19 end proc


CodeGeneration['C']( to_translate );


Warning, procedure/module options ignored
double to_translate (double x)
{
  return(r);
}

Instead of using the value for 'r' passed in, CodeGenerate is producing a function which returns the bare symbol 'r' which is treated as a double. It shouldn't be an issue with lazy evalution because 'to_translate' is evaluated on the statement before the call to CodeGeneration, and to_translate has the full expression that I want to generate code for. How do I get CodeGeneration to produce the intented result?

Please Wait...