# Syntax error when using @ode\_def inside a function

**URL:** <https://discourse.julialang.org/t/syntax-error-when-using-ode-def-inside-a-function/28171>\
**Category:** General Usage\
**Tags:** diffeq, syntax\
**Created:** [August 29, 2019, 3:52pm UTC](https://discourse.julialang.org/t/syntax-error-when-using-ode-def-inside-a-function/28171 "2019-08-29T15:52:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Geometh](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@Geometh](https://discourse.julialang.org/u/Geometh)\
**Post date:** [August 29, 2019, 3:52pm UTC](https://discourse.julialang.org/t/syntax-error-when-using-ode-def-inside-a-function/28171/1 "2019-08-29T15:52:27Z")

</div>

Hi there,

I wanted to use the @ode\_def macro from the ParametrizedFunctions package inside some custom function. However, I get a syntax error saying: `syntax: "struct" expression not at top level`.

Here is a minimum working example:

```julia
using ParameterizedFunctions

function mwe()
        f = @ode_def begin
            dx=a
        end a
    a=1j
end

```

I run it in atom 1.38.1 using julia 1.1.0. on an ubuntu linux.  
What is it I am doing wrong?

Thanks for your help  
G

---

<div class="post-metadata">

**Author:** ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Post date:** [August 29, 2019, 4:07pm UTC](https://discourse.julialang.org/t/syntax-error-when-using-ode-def-inside-a-function/28171/2 "2019-08-29T16:07:03Z")

</div>

Here’s why: the macro expands to define a new type, and that is something you’re not allowed to do within a function:

```julia
julia> @macroexpand @ode_def begin
                   dx=a
               end a
quote
    mutable struct var"##402"{var"#43#F", var"#44#J", var"#45#T", var"#46#W", var"#47#Wt", var"#48#PJ", var"#49#TT1", var"#50#TT2"} <: (ParameterizedFunctions.DiffEqBase).AbstractParameterizedFunction{true}
    ...

```
