# Modify a Expr to generate a new Expr

**URL:** <https://discourse.julialang.org/t/modify-a-expr-to-generate-a-new-expr/79368>\
**Category:** New to Julia\
**Created:** [April 12, 2022, 8:30am UTC](https://discourse.julialang.org/t/modify-a-expr-to-generate-a-new-expr/79368 "2022-04-12T08:30:25Z")\
**Posts on this page:** 5\
**Page:** 1

<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:** [April 12, 2022, 8:30am UTC](https://discourse.julialang.org/t/modify-a-expr-to-generate-a-new-expr/79368/1 "2022-04-12T08:30:25Z")

</div>

Is there a way I can removing “(” and “)” in an Expr, like this:

The orignal Expr:

```julia
origin=:((10 |> x->x+2) |> x->x+3)

```

New target Expr:

```julia
target=:(10 |> x->x+2 |> x->x+3)

```

It has following this rules:

only the “( )” from two sides of `|>` is needed to be removed.

So, this Expr

```julia
origin2=:((10 |> (x->x+2)) |> x->x+3)

```

of which the target is

```julia
target2=(10 |> (x->x+2) |> x->x+3) 

```

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [April 12, 2022, 10:22am UTC](https://discourse.julialang.org/t/modify-a-expr-to-generate-a-new-expr/79368/2 "2022-04-12T10:22:17Z")

</div>

Often during printing, expressions are shown with more parentheses than technically necessary. You therefore can’t “remove” the parentheses from an expression. Two examples:

Redundant parentheses disappear after parsing:

```julia
julia> :((((x + y))))
:(x + y)

```

Clarifying parentheses appear when showing an expression:

```julia
julia> :(x |> y |> z)
:((x |> y) |> z)

```

---

<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:** [April 12, 2022, 12:00pm UTC](https://discourse.julialang.org/t/modify-a-expr-to-generate-a-new-expr/79368/3 "2022-04-12T12:00:49Z")

</div>

Yes, in printing, it is. But it matters more than printing. For example:

this repl can run correctly:

```julia
1 |> xx->xx+1 |> x->x+2-xx
 
3

```

while this one can not:

```julia
(1 |> xx->xx+1) |> x->x+2-xx

UndefVarError: xx not defined

```

---

<div class="post-metadata">

**Author:** ![JonasIsensee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonasisensee/32/4704_2.png) [@JonasIsensee](https://discourse.julialang.org/u/JonasIsensee)\
**Post date:** [April 12, 2022, 12:39pm UTC](https://discourse.julialang.org/t/modify-a-expr-to-generate-a-new-expr/79368/4 "2022-04-12T12:39:24Z")

</div>

this “works” in the REPL, but are you certain that it does what you think it does?

your definition is equivalent to

```julia
innerfun(x, xx) = x+2-xx
outerfun(xx) = innerfun(xx+1, xx)
outerfun(1) 

```

```julia
julia> :(x |> y |> z)
:((x |> y) |> z)

julia> :(x |> y->y |> z)
:(x |> (y->begin
              #= REPL[10]:1 =#
              y |> z
          end))

```

---

<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:** [April 12, 2022, 1:10pm UTC](https://discourse.julialang.org/t/modify-a-expr-to-generate-a-new-expr/79368/5 "2022-04-12T13:10:13Z")

</div>

Oh, I see. I had been wrong understanding on this type of pip function.  
Thank you for your reply.
