Including generated code

Hi,

I am doing some calculations with maxima and wanna use the results in rust.

For example I exported from maxima:

let G_k69 = dt;
let G_k77 = 1;
let G_k710 = dt;
let G_k81 = dt*(2*a_zm_b*q2-2*a_ym_b*q3);
let G_k82 = dt*(2*a_zm_b*q3+2*a_ym_b*q2);
let G_k83 = dt*(-(4*a_xm_b*q2)+2*a_ym_b*q1+2*a_zm_b*q0);
let G_k84 = dt*(-(4*a_xm_b*q3)+2*a_zm_b*q1-2*a_ym_b*q0);
let G_k88 = 1;
let G_k91 = dt*(2*a_xm_b*q3-2*a_zm_b*q1);
let G_k92 = dt*(2*a_xm_b*q2-4*a_ym_b*q1-2*a_zm_b*q0);
let G_k93 = dt*(2*a_zm_b*q3+2*a_xm_b*q1);
let G_k94 = dt*(-(4*a_ym_b*q3)+2*a_zm_b*q2+2*a_xm_b*q0);
let G_k99 = 1;
let G_k101 = dt*(2*a_ym_b*q1-2*a_xm_b*q2);
let G_k102 = dt*(2*a_xm_b*q3-4*a_zm_b*q1+2*a_ym_b*q0);
let G_k103 = dt*(2*a_ym_b*q3-4*a_zm_b*q2-2*a_xm_b*q0);
let G_k104 = dt*(2*a_ym_b*q2+2*a_xm_b*q1);
let G_k1010 = 1;
let G_k1111 = 1;
let G_k1212 = 1;
let G_k1313 = 1;
// Calculate next states
self.q0 = -((dt*q3*w_z_b)/2)-(dt*q2*w_y_b)/2-(dt*q1*w_x_b)/2+q0;
self.q1 = (dt*q2*w_z_b)/2-(dt*q3*w_y_b)/2+(dt*q0*w_x_b)/2+q1;
self.q2 = -((dt*q1*w_z_b)/2)+(dt*q0*w_y_b)/2+(dt*q3*w_x_b)/2+q2;
self.q3 = (dt*q0*w_z_b)/2+(dt*q1*w_y_b)/2-(dt*q2*w_x_b)/2+q3;

Now I wanna use that codesnipped and tried the include!() macro, but with no success: expected expression, found let statement

What is the proper way to include generated code. The code shall generate some variables and overwriting some variables from the object it self.

How did you use that macro? It should be working as if you've just copy-pasted this code at the place of macro, so placing it directly in function body, for example, should show no errors.

This is what I tried. I added the include!() inside of the function body.

According to the include docs, emphasis mine:

Parses a file as an expression or an item according to the context.

The contents of your file is neither an expression, nor an item, it is a sequence of statements. You can convert a sequence of statements into an expression by wrapping them in a block { ... } to create a block expression.

3 Likes

Thanks I will try this out. In the meantime I generated full rust functions and using them as modules