Hello,

I am trying to use IntervalConstraintProgramming & associated packages to solve a geometric feasibility problem. In order to be able to use functions in constraints, the ICP package provides a macro for function definitions.

For example, one such function looks like this (phi1 is going to be an interval):

@function calc_a3(phi1) = sqrt($a1^2 + $a2^2 - 2*$a1*$a2*cos(phi1));

I can go further and embed those functions in each other (both phis are intervals here):

@function calc_l2_phi2(phi1,phi2) = (

a3 = calc_a3(phi1);

cos(phi2) * a3

)

Constraint creation with these functions works like this:

@constraint $r - calc_a3(phi1) < 0

In Julia, you can refer to variables in functions from the scope the function was created in:

r = 5

get_r() = r

I want to achieve something similar using the @function macro (I could probably work around it, but it would make my life easier), but I have no clue about how quoting, AST parsing, etc works in macros, so I have tried the following at random (hoping that a Shakespeare sonnet comes out):

@function get_r() =

$r, :(r ), :($r)

but none of these could be âflattenedâ.

Any help is appreciated!