# @variables as function parameter

**URL:** <https://discourse.julialang.org/t/variables-as-function-parameter/31650>\
**Category:** Numerics\
**Tags:** intervals\
**Created:** [November 29, 2019, 9:50am UTC](https://discourse.julialang.org/t/variables-as-function-parameter/31650 "2019-11-29T09:50:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cvanaret](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cvanaret/32/11594_2.png) [@cvanaret](https://discourse.julialang.org/u/cvanaret)\
**Post date:** [November 29, 2019, 9:50am UTC](https://discourse.julialang.org/t/variables-as-function-parameter/31650/1 "2019-11-29T09:50:58Z")

</div>

Hi,  
I started playing with the IntervalConstraintProgramming module in Julia, and ran into a problem.  
Here is a minimal example:

```julia
using IntervalConstraintProgramming
using IntervalArithmetic
using ModelingToolkit

function test(X, vars)
	hc4 = Contractor(vars, x + y)
	return hc4(0..0, X)
end

vars = @variables x y
X = IntervalBox(0..5, 0..Inf)
new_X = test(X, vars)

```

and I get:

```julia
ERROR: MethodError: no method matching (::getfield(IntervalConstraintProgramming, Symbol("##53#54")))(::IntervalBox{2,Float64})
The applicable method may be too new: running in world age 25183, while current world is 25185.
Closest candidates are:
  #53(::Any) at /u/v/vanaret/.julia/packages/IntervalConstraintProgramming/MlctF/src/code_generation.jl:192 (method too new to be called from this world context.)
Stacktrace:
 [1] (::IntervalConstraintProgramming.GeneratedFunction{getfield(IntervalConstraintProgramming, Symbol("##53#54"))})(::IntervalBox{2,Float64}) at /u/v/vanaret/.julia/packages/IntervalConstraintProgramming/MlctF/src/code_generation.jl:12
 [2] contract(::Contractor{2,1,getfield(IntervalConstraintProgramming, Symbol("##53#54")),getfield(IntervalConstraintProgramming, Symbol("##55#56")),Operation}, ::IntervalBox{1,Float64}, ::IntervalBox{2,Float64}) at /u/v/vanaret/.julia/packages/IntervalConstraintProgramming/MlctF/src/contractor.jl:54
 [3] (::Contractor{2,1,getfield(IntervalConstraintProgramming, Symbol("##53#54")),getfield(IntervalConstraintProgramming, Symbol("##55#56")),Operation})(::IntervalBox{1,Float64}, ::IntervalBox{2,Float64}) at /u/v/vanaret/.julia/packages/IntervalConstraintProgramming/MlctF/src/contractor.jl:78
 [4] (::Contractor{2,1,getfield(IntervalConstraintProgramming, Symbol("##53#54")),getfield(IntervalConstraintProgramming, Symbol("##55#56")),Operation})(::Interval{Float64}, ::IntervalBox{2,Float64}) at /u/v/vanaret/.julia/packages/IntervalConstraintProgramming/MlctF/src/contractor.jl:82
 [5] test(::IntervalBox{2,Float64}, ::Tuple{Variable,Variable}) at ./REPL[36]:3
 [6] top-level scope at none:0

```

Does it have to do with the @variables passed as function parameter? The error mentions the code generation of the contractor, and my knowledge of Julia is too limited to understand.  
Thanks for your help,

Charlie

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [December 3, 2019, 5:11pm UTC](https://discourse.julialang.org/t/variables-as-function-parameter/31650/2 "2019-12-03T17:11:17Z")

</div>

> [@cvanaret](#):
>
> X = IntervalBox(0…5, 0…Inf)

This is a major issue in Julia when generating code and using `@eval`.  
Basically you have to go back up to “top level” (outside any functions) before using functions that are defined like this.

You could rewrite your code like this:

```julia

julia> function make_contractor(vars)
               hc4 = Contractor(vars, x + y)
               return hc4
       end
test (generic function with 2 methods)

julia> hc4 = make_contractor(vars);

julia> function run_contractor(C, X)
           return C(0..0, X)
       end

julia> run_contractor(hc4, X)
[0, 0] × [0, 0]

```
