# Why is this a "malformed expression"?

**URL:** <https://discourse.julialang.org/t/why-is-this-a-malformed-expression/86391>\
**Category:** General Usage\
**Tags:** question, syntax\
**Created:** [August 26, 2022, 3:40pm UTC](https://discourse.julialang.org/t/why-is-this-a-malformed-expression/86391 "2022-08-26T15:40:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [August 26, 2022, 3:40pm UTC](https://discourse.julialang.org/t/why-is-this-a-malformed-expression/86391/1 "2022-08-26T15:40:19Z")

</div>

```julia
julia> import Base: first

julia> (first((t,)), b) = 3, 5
ERROR: syntax: malformed expression
Stacktrace:
 [1] top-level scope
   @ REPL[23]:1

julia> first((t,)) = 3; #DON'T DO THIS, MESSES UP REPL DISPLAY

julia> (first(t), b) = 3, 5; #DON'T DO THIS, MESSES UP REPL DISPLAY

```

The last two lines do not produce any error (though redefining `first` like this messes up the REPL for the rest of the session), but the one previous to them, `(first((t,)), b) = 3, 5` leads to a “malformed expression” error.

(I came across this while looking into [Issue#46482](https://github.com/JuliaLang/julia/issues/46482). It’s somewhat orthogonal to the original issue mentioned, and there may be a reasonable explanation I’m missing, so I’m posting it here.)

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [August 27, 2022, 2:13pm UTC](https://discourse.julialang.org/t/why-is-this-a-malformed-expression/86391/2 "2022-08-27T14:13:57Z")

</div>

Well, it’s definitely not surprising that these expressions are malformed. The `SYSTEM (REPL): showing an error caused an error` errors seem like something that should be reported to the issue tracker, though.

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [August 27, 2022, 8:41pm UTC](https://discourse.julialang.org/t/why-is-this-a-malformed-expression/86391/3 "2022-08-27T20:41:59Z")

</div>

> [@nsajko](#):
>
> The `SYSTEM (REPL): showing an error caused an error` errors seem like something that should be reported to the issue tracker, though.

`SYSTEM (REPL): showing an error caused an error ` is not really surprising either. Redefining the method `Base.first(t::Tuple)` is type piracy. `first` is used multiple times in [the source code of the REPL](https://github.com/JuliaLang/julia/blob/d2aedf48ca799cbe11c6db9188e8af9ee5340e5f/stdlib/REPL/src/REPL.jl) so it is not surprising that redefining a method will cause the REPL malfunctioning.

---

<div class="post-metadata">

**Author:** ![Stephen\_Vavasis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephen_vavasis/32/3389_2.png) [@Stephen\_Vavasis](https://discourse.julialang.org/u/Stephen_Vavasis)\
**Post date:** [August 28, 2022, 12:37am UTC](https://discourse.julialang.org/t/why-is-this-a-malformed-expression/86391/4 "2022-08-28T00:37:14Z")

</div>

Another issue raised by this post: Is it OK to use multiple LHS assignment when defining one-line functions? It seems that Julia (1.7.1) is inconsistent on this matter:

```julia
julia> f(x),g(x)=3,5;

julia> f(12) + g('a')
8

julia> f(x),g(x)=x*x,x*x*x
ERROR: UndefVarError: x not defined
Stacktrace:
 [1] top-level scope
   @ REPL[22]:1

```

Maybe this deserves a second issue?

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [August 28, 2022, 12:55am UTC](https://discourse.julialang.org/t/why-is-this-a-malformed-expression/86391/5 "2022-08-28T00:55:40Z")

</div>

Interesting find, seems like it deserves a Github issue.

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [August 28, 2022, 12:58am UTC](https://discourse.julialang.org/t/why-is-this-a-malformed-expression/86391/6 "2022-08-28T00:58:56Z")

</div>

> [@aramirezreyes](#):
>
> `SYSTEM (REPL): showing an error caused an error ` is not really surprising either.

Yeah, this part is not surprising to me; I mentioned it just as a warning for people here who might want to try it out in their existing sessions (and end up with a messed up REPL).

Perhaps avoiding `first` and using a different example would make things clearer:

```julia
julia> foo((t, )), b = 3, 5
ERROR: syntax: malformed expression
Stacktrace:
 [1] top-level scope
   @ REPL[1]:1

julia> foo((t, )) = 3
foo (generic function with 1 method)

julia> foo(t), b = 3, 5
(3, 5)

```

> [@Stephen\_Vavasis](#):
>
> Another issue raised by this post: Is it OK to use multiple LHS assignment when defining one-line functions?

This is sort of what I was getting at as the main issue in the post, I just didn’t word it clearly enough. Specifically, it _seems_ like it should be ok, since `foo(t), b = 3, 5` works, but `foo((t, )), b = 3, 5`, which should be the same thing but with a tuple-destructuring argument, leads to a `malformed expression` error.

---

<div class="post-metadata">

**Author:** ![Stephen\_Vavasis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephen_vavasis/32/3389_2.png) [@Stephen\_Vavasis](https://discourse.julialang.org/u/Stephen_Vavasis)\
**Post date:** [August 28, 2022, 3:05am UTC](https://discourse.julialang.org/t/why-is-this-a-malformed-expression/86391/7 "2022-08-28T03:05:23Z")

</div>

OK, I opened an issue: [Disallow multiple LHS assignment for one-line function definitions · Issue #46517 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/46517)
