Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide output on assignment #312

Merged
merged 2 commits into from
Nov 12, 2021
Merged

Hide output on assignment #312

merged 2 commits into from
Nov 12, 2021

Conversation

ankane
Copy link
Contributor

@ankane ankane commented Oct 24, 2021

Hi, this PR hides output on assignment (like Python). This avoids the need to add ; nil to lines. It uses assignment_expression? from IRB and checks that it exists first for older versions (added in ruby/irb@0a3a0f5).

Ref: #195

@kojix2 kojix2 requested a review from mrkn October 25, 2021 07:14
@kojix2
Copy link
Member

kojix2 commented Oct 25, 2021

In my case, if I don't want it to output, I often put a 0 in the last line. However, I'm neutral on this matter because I don't really care about it. If more people want to change it, it should be changed. What do you think, @mrkn, the owner?

@kojix2 kojix2 requested review from mrkn and removed request for mrkn November 11, 2021 12:56
@mrkn
Copy link
Contributor

mrkn commented Nov 11, 2021

I have a plan to implement the output prevention by putting single semicolon at the end of the cell. It is the same behavior as IJulia.

@kojix2
Copy link
Member

kojix2 commented Nov 11, 2021

I found a very interesting issue on IJulia, the kernel of the Julia language.
JuliaLang/IJulia.jl#649

In IPython, something like x = np.arange(1000) shows no output, whereas in IJulia x = collect(1:1000) does. I understand this matches the REPL, but is there a way to surpress this by default other than adding semicolons everywhere?

No. When you evaluate a cell in IJulia, it is just returns the value of the last expression, and what you are seeing here is a difference between the Julia and Python languages.
In Python, assignment expressions don't have a value, whereas in Julia the assignment x = y has the value y.

In Python and R, assignment expressions do not have a value, but in Julia and Ruby, assignment expressions have a value, so it is more natural to show the value.However, even in the Julia language, there seems to be an argument that the output should be hidden for usability. I was thinking of merging this pull request, but after seeing Julia's policy, I decided to put it on hold again.

@mrkn
Copy link
Contributor

mrkn commented Nov 11, 2021

By the way, I want to merge this if this behavior can be opt-in by a configuration like below.

IRuby.silent_assignment = true

@ankane Could you make this configurable? The default configuration should be disable for compatibility.

@kojix2
Copy link
Member

kojix2 commented Nov 11, 2021

I agree with the semicolon!

@mrkn
Copy link
Contributor

mrkn commented Nov 11, 2021

In Julia and Ruby, an assignment is an expression so it has a value, whereas an assignment in Python isn't an expression but a statement so it doesn't have a value.

@ankane
Copy link
Contributor Author

ankane commented Nov 12, 2021

Added an option and made it opt-in.

@mrkn
Copy link
Contributor

mrkn commented Nov 12, 2021

@ankane Thank you so much!

@mrkn mrkn merged commit e26a216 into SciRuby:master Nov 12, 2021
@ankane
Copy link
Contributor Author

ankane commented Nov 12, 2021

That was fast 🔥 Thanks @mrkn and @kojix2!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants