Brian1
April 12, 2022, 8:30am
1
Is there a way I can removing “(” and “)” in an Expr, like this:
The orignal Expr:
origin=:((10 |> x->x+2) |> x->x+3)
New target Expr:
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
origin2=:((10 |> (x->x+2)) |> x->x+3)
of which the target is
target2=(10 |> (x->x+2) |> x->x+3)
jules
April 12, 2022, 10:22am
2
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> :((((x + y))))
:(x + y)
Clarifying parentheses appear when showing an expression:
julia> :(x |> y |> z)
:((x |> y) |> z)
1 Like
Brian1
April 12, 2022, 12:00pm
3
Yes, in printing, it is. But it matters more than printing. For example:
this repl can run correctly:
1 |> xx->xx+1 |> x->x+2-xx
3
while this one can not:
(1 |> xx->xx+1) |> x->x+2-xx
UndefVarError: xx not defined
this “works” in the REPL, but are you certain that it does what you think it does?
your definition is equivalent to
innerfun(x, xx) = x+2-xx
outerfun(xx) = innerfun(xx+1, xx)
outerfun(1)
julia> :(x |> y |> z)
:((x |> y) |> z)
julia> :(x |> y->y |> z)
:(x |> (y->begin
#= REPL[10]:1 =#
y |> z
end))
2 Likes
Brian1
April 12, 2022, 1:10pm
5
Oh, I see. I had been wrong understanding on this type of pip function.
Thank you for your reply.
1 Like