# Can I concatenate expressions in macro?

**URL:** <https://discourse.julialang.org/t/can-i-concatenate-expressions-in-macro/69220>\
**Category:** General Usage\
**Created:** [October 5, 2021, 7:48am UTC](https://discourse.julialang.org/t/can-i-concatenate-expressions-in-macro/69220 "2021-10-05T07:48:33Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![albheim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albheim/32/34660_2.png) [@albheim](https://discourse.julialang.org/u/albheim)\
**Post date:** [October 5, 2021, 9:13am UTC](https://discourse.julialang.org/t/can-i-concatenate-expressions-in-macro/69220/2 "2021-10-05T09:13:42Z")

</div>

You could look at how a block of expressions is normally represented and try to rebuild that. For example

```julia
julia> a = quote
       a = 1+1
       b = a + 4
       end
quote
    #= REPL[16]:2 =#
    a = 1 + 1
    #= REPL[16]:3 =#
    b = a + 4
end

julia> dump(a)
Expr
  head: Symbol block
  args: Array{Any}((6,))
    1: LineNumberNode
      line: Int64 2
      file: Symbol REPL[16]
    2: Expr
      head: Symbol =
      args: Array{Any}((2,))
        1: Symbol a
        2: Expr
          head: Symbol call
          args: Array{Any}((3,))
            1: Symbol +
            2: Int64 1
            3: Int64 1
    3: LineNumberNode
      line: Int64 3
      file: Symbol REPL[16]
    4: Expr
      head: Symbol =
      args: Array{Any}((2,))
        1: Symbol b
        2: Expr
          head: Symbol call
          args: Array{Any}((3,))
            1: Symbol +
            2: Symbol a
            3: Int64 4

```

Here the `LineNumberNode` is not interesting, but what we see is that we just have an expression with `head` being `:block`, and the remaining expressions are in the `args`. So if you have an array with expressions you could probably do something along the lines of

```julia
macro mymacro(args...)
    exprs = preprocess(args) # Whatever you do to create the expression list
    Expr(:block, exprs...) # Create a block expression with all sub-expressions
end

```

---

_[View the full topic](https://discourse.julialang.org/t/can-i-concatenate-expressions-in-macro/69220)._
