# REPL Trailing Semicolon Behavior

**URL:** <https://discourse.julialang.org/t/repl-trailing-semicolon-behavior/13672>\
**Category:** General Usage\
**Created:** [August 18, 2018, 6:31pm UTC](https://discourse.julialang.org/t/repl-trailing-semicolon-behavior/13672 "2018-08-18T18:31:51Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [August 18, 2018, 6:31pm UTC](https://discourse.julialang.org/t/repl-trailing-semicolon-behavior/13672/1 "2018-08-18T18:31:51Z")

</div>

Question: when does a trailing ‘;’ suppress output?

```julia
using DataFrames, CategoricalArrays
df= DataFrame( nm= [1, 2, 3] )
df[:nm]= recode( df[:nm], 9801=>(-4) ); ## why does trailing ; not suppress output??
df; ## suppresses just fine

```

without the comment, the recode suppresses output. with the comment, it does not.

the last statement always suppresses output, regardless of subsequent comment.

could someone please explain why this is so?

regards,

/iaw

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [August 18, 2018, 7:38pm UTC](https://discourse.julialang.org/t/repl-trailing-semicolon-behavior/13672/2 "2018-08-18T19:38:38Z")

</div>

Both of your lines are silent for me. Note though that `;` does not suppress output in general, it just suppress output of printing of the final result, so e.g. printing to `stdout` is not suppressed:

```julia
julia> function foo()
           println("Hello")
           return "Hello"
       end
foo (generic function with 1 method)

julia> foo()
Hello
"Hello"

julia> foo();
Hello

```

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [August 18, 2018, 7:54pm UTC](https://discourse.julialang.org/t/repl-trailing-semicolon-behavior/13672/3 "2018-08-18T19:54:09Z")

</div>

thx, f. I know about the printing functions. alas, here is an exact copy and paste:

```julia
> /Applications/Julia-1.0.app/Contents/Resources/julia/bin/julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.0.0 (2018-08-08)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia> using DataFrames, CategoricalArrays

julia> df= DataFrame( nm= [1, 2, 3] )
3×1 DataFrame
│ Row │ nm │
├─────┼────┤
│ 1 │ 1 │
│ 2 │ 2 │
│ 3 │ 3 │

julia> df[:nm]= recode( df[:nm], 9801=>(-4) ); ## why does trailing ; not suppress output??
3-element Array{Int64,1}:
 1
 2
 3

julia> df; ## suppresses just fine

```

is your output different??

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [August 18, 2018, 7:58pm UTC](https://discourse.julialang.org/t/repl-trailing-semicolon-behavior/13672/4 "2018-08-18T19:58:43Z")

</div>

Oh, fun little bug. Seems like the detection is fooled by your additional comments and `;` on the same line, see e.g.

```julia
julia> f() = 1;

julia> f(); # ; a
1

```

but if you only use have

```julia
df[:nm]= recode( df[:nm], 9801=>(-4) );

```

then it works correctly.

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [August 18, 2018, 8:02pm UTC](https://discourse.julialang.org/t/repl-trailing-semicolon-behavior/13672/5 "2018-08-18T20:02:56Z")

</div>

thanks. I will file a bug report.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [August 19, 2018, 11:02am UTC](https://discourse.julialang.org/t/repl-trailing-semicolon-behavior/13672/6 "2018-08-19T11:02:16Z")

</div>

That’s a (kind of) [known issue](https://github.com/JuliaLang/julia/blob/a288a2dae4193c245205b05055869d115b08bdba/stdlib/REPL/src/REPL.jl#L1060).

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [August 19, 2018, 6:36pm UTC](https://discourse.julialang.org/t/repl-trailing-semicolon-behavior/13672/7 "2018-08-19T18:36:20Z")

</div>

If someone wanted to fix this, the fix would certainly be welcomed, but doing it correctly probably requires a Julia parser like [CSTParser](https://github.com/ZacLN/CSTParser.jl) that preserves all input in the parse result—or at least a full tokenizer that preserves all input. We eventually want something like that so that we can give better parser errors and/or do syntax highlighting in the REPL, but it’s a non-trivial project.

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [August 19, 2018, 10:14pm UTC](https://discourse.julialang.org/t/repl-trailing-semicolon-behavior/13672/8 "2018-08-19T22:14:55Z")

</div>

for now, it may be better just to muddle along and fix buglets as they are noticed, rather than to introduce a full julia parser (which will take more exec time, too).

I think it is a weakness that it is not so easy to parse julia (at least superficially). For example, when I want to determine where the current statement ends, and the command line should be coming back.

(I had hoped to convince you guys to make `endif`, `end...` aliases for end, which in many cases can make not only parsing but also quickly looking at code easier, and without invalidating existing syntax. alas, I understand that this is just one opinion.)

looking at the referenced code, what is a comment\_multi in julia?

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [August 19, 2018, 11:45pm UTC](https://discourse.julialang.org/t/repl-trailing-semicolon-behavior/13672/9 "2018-08-19T23:45:23Z")

</div>

We’re already parsing, it’s just that the parser throws out extraneous stuff like irrelevant trailing semicolons. Julia’s syntax is not particularly complicated and certainly simpler than C++, Ruby, Perl and other common languages (which all have undecidable syntax, iirc). Many languages require runtime information to parse, which Julia does not. It is much more complex than Lisp, but then again so is everything.

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [August 20, 2018, 12:03am UTC](https://discourse.julialang.org/t/repl-trailing-semicolon-behavior/13672/10 "2018-08-20T00:03:14Z")

</div>

or BASIC? 😉 (actually, I have not used basic for years, so I could be wrong here, too.) perl seems completely unparseable. I think perl 6.0 is the first version to specify the language separately from whatever its parser does. python and fortran used to be reasonably parseable.

so I think you are correct. still, indulge me and let me nudge for my matching `end.*` aliases to `end` … 😉
