# UndefVarError when including a snippet of code

**URL:** <https://discourse.julialang.org/t/undefvarerror-when-including-a-snippet-of-code/2376>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 1, 2017, 1:05am UTC](https://discourse.julialang.org/t/undefvarerror-when-including-a-snippet-of-code/2376 "2017-03-01T01:05:54Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 1, 2017, 2:08am UTC](https://discourse.julialang.org/t/undefvarerror-when-including-a-snippet-of-code/2376/5 "2017-03-01T02:08:50Z")

</div>

> [@yuyichao](#):
>
> include works in global scope. It’s not possible to make it reference local variables.

Ahh yeah, that’s it.

If you want to do compile time copy/paste, use a macro. Here’s a version which works on v0.5 and v0.6.

> [@\`@def\` macro generator broken on master](https://discourse.julialang.org/t/def-macro-generator-broken-on-master/1096/3):
>
> I see, name wasn’t escaped: macro def(name, definition) return quote macro $(esc(name))() esc($(Expr(:quote, definition))) end end end @def test begin a = 2 end # Now @test "pastes" the code `a=2` is good now.

---

_[View the full topic](https://discourse.julialang.org/t/undefvarerror-when-including-a-snippet-of-code/2376)._
