Question: when does a trailing ‘;’ suppress output?
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?
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> function foo()
foo (generic function with 1 method)
thx, f. I know about the printing functions. alas, here is an exact copy and paste:
_ _ _(_)_ | 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 ] )
│ Row │ nm │
│ 1 │ 1 │
│ 2 │ 2 │
│ 3 │ 3 │
julia> df[:nm]= recode( df[:nm], 9801=>(-4) ); ## why does trailing ; not suppress output??
julia> df; ## suppresses just fine
is your output different??
Oh, fun little bug. Seems like the detection is fooled by your additional comments and
; on the same line, see e.g.
julia> f() = 1;
julia> f(); # ; a
but if you only use have
df[:nm]= recode( df[:nm], 9801=>(-4) );
then it works correctly.
thanks. I will file a bug report.
That’s a (kind of) known issue.
If someone wanted to fix this, the fix would certainly be welcomed, but doing it correctly probably requires a Julia parser like CSTParser 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.
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
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?
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.
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