# Macro: no method matching size

**URL:** <https://discourse.julialang.org/t/macro-no-method-matching-size/40311>\
**Category:** General Usage\
**Tags:** macros\
**Created:** [May 28, 2020, 2:57am UTC](https://discourse.julialang.org/t/macro-no-method-matching-size/40311 "2020-05-28T02:57:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BMval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmval/32/7647_2.png) [@BMval](https://discourse.julialang.org/u/BMval)\
**Post date:** [May 28, 2020, 2:57am UTC](https://discourse.julialang.org/t/macro-no-method-matching-size/40311/1 "2020-05-28T02:57:03Z")

</div>

Would you help me with Macros

Why macros does not see functions: size() or length()?

Julia ver 1.1.1

```julia
macro test_macro(e::Expr)
	return (ones(size(e)[1]) .+ e)
end

MethodError: no method matching size(::Expr)
Closest candidates are:
  size(!Matched::BitArray{1}) at bitarray.jl:77
  size(!Matched::BitArray{1}, !Matched::Any) at bitarray.jl:81
  size(!Matched::Core.Compiler.StmtRange) at show.jl:1561
  ...

Stacktrace:
 [1] @test_macro(::LineNumberNode, ::Module, ::Expr) at ./In[96]:4774:

```

Julia ver 1.3 error

```julia
LoadError: MethodError: no method matching size(::Expr)
Closest candidates are:
  size(!Matched::BitArray{1}) at bitarray.jl:77
  size(!Matched::BitArray{1}, !Matched::Integer) at bitarray.jl:81
  size(!Matched::Core.Compiler.StmtRange) at show.jl:1598
  ...
in expression starting at G:\My Drive\Booth\Political_firms\Programs\Jl\TopicModeling_v1.jl:127
@test_macro3(::LineNumberNode, ::Module, ::Expr) at TopicModeling_v1.jl:133

```

---

<div class="post-metadata">

**Author:** ![benninkrs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/benninkrs/32/3191_2.png) [@benninkrs](https://discourse.julialang.org/u/benninkrs)\
**Post date:** [May 28, 2020, 3:27am UTC](https://discourse.julialang.org/t/macro-no-method-matching-size/40311/2 "2020-05-28T03:27:42Z")

</div>

Macros operate on expressions, not values. That is, they input and output Julia code. So you can’t check the size of `e` or add `e` to anything, because `e` is an expression, not an array. What you can do instead is this:

```julia
macro test_macro2(e::Expr)
	return esc( :( ones(size($e)[1]) .+ $e) )
end

```

Then `@test_macro2 [a,b,c]` will return the expression `ones(size([a,b,c][1]) .+ [a,b,c]` which is then evaluated _outside the macro_. Contrast this with

```julia
function test_func(a::Array)
	return (ones(size(a)[1]) .+ a)
end

```

Then when you write `test_func([a,b,c])`, `[a,b,c]` is evaluated _first_, and the resulting array is bound to `a` inside `test_func`, which uses it to construct a new array.

---

<div class="post-metadata">

**Author:** ![BMval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmval/32/7647_2.png) [@BMval](https://discourse.julialang.org/u/BMval)\
**Post date:** [May 28, 2020, 3:51am UTC](https://discourse.julialang.org/t/macro-no-method-matching-size/40311/3 "2020-05-28T03:51:28Z")

</div>

Thank you so much
