# How does Julia merge several exprs to one expr?

**URL:** <https://discourse.julialang.org/t/how-does-julia-merge-several-exprs-to-one-expr/77498>\
**Category:** New to Julia\
**Created:** [March 7, 2022, 9:45am UTC](https://discourse.julialang.org/t/how-does-julia-merge-several-exprs-to-one-expr/77498 "2022-03-07T09:45:38Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Brian1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brian1/32/49250_2.png) [@Brian1](https://discourse.julialang.org/u/Brian1)\
**Post date:** [March 7, 2022, 11:26am UTC](https://discourse.julialang.org/t/how-does-julia-merge-several-exprs-to-one-expr/77498/4 "2022-03-07T11:26:29Z")

</div>

Thanks a lot to your help and your advice.  
In broader context, my target is to creat a set of local varialbes. Firstly, create a NamedTuple came to my mind, but in practise, that is not convinient. So now I can get the target just like this:

```julia
macro localvars(expr)
    bb=[]
    for cc in expr.args
        if cc isa Expr && cc.head==:(=)
            append!(bb,[cc.args[1]])
        end
    end
    cvv=Expr(:tuple,(:($x=$x) for x in bb)...)
    bbres=quote
        let
            $expr
            $cvv
        end
    end |> esc
end

vars=@localvars begin
    a=1
    b=2
    c=a+b
end 

vars.a
vars.c

```

This is a little convinient for me

---

_[View the full topic](https://discourse.julialang.org/t/how-does-julia-merge-several-exprs-to-one-expr/77498)._
