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

clear/remove names from repl #2385

Closed
pao opened this issue Feb 22, 2013 · 31 comments
Closed

clear/remove names from repl #2385

pao opened this issue Feb 22, 2013 · 31 comments
Labels
REPL Julia's REPL (Read Eval Print Loop)

Comments

@pao
Copy link
Member

pao commented Feb 22, 2013

This is rapidly becoming a frequently-requested feature, and there doesn't appear to be a current tracking issue for it, so this will at least give me something to point to.

I think it would be acceptable if this only works from the REPL, though others may disagree.

@milktrader
Copy link
Contributor

+1 for clutter removal functionality.

R uses the rm() function to remove individual objects rm(foo) or the entire variable list rm(list=ls())

@diegozea
Copy link
Contributor

+1

In R rm(); gc() is a vital tuple sometimes

@StefanKarpinski
Copy link
Member

This is probably Jeff's most hated feature request.

@pao
Copy link
Member Author

pao commented Feb 22, 2013

Maybe so, but users expect it. Making restarts fast is another possibility.

@diegozea
Copy link
Contributor

Related to this: #482

@mlubin
Copy link
Member

mlubin commented Feb 22, 2013

I'd much rather have faster restarts.

@diegozea
Copy link
Contributor

This can be related to this too: #1195

@pao
Copy link
Member Author

pao commented Feb 22, 2013

Thanks, I had been looking for that and forgot what it was called.

@catawbasam
Copy link
Contributor

+1

@nalimilan
Copy link
Member

What is the problem with this feature exactly? :-) Are there technical problems with hiding a variable, even if it's only freed at the next gc?

For reference, the thread I found about this is: https://groups.google.com/forum/#!msg/julia-dev/OTISvMKcr14/6fzuHO1St78J

JeffBezanson added a commit that referenced this issue Jul 1, 2014
a link to the previous Main called LastMain is provided.
`using LastMain.Package` works to restore access to loaded libraries.

fixes #1195, fixes #2385
@milktrader
Copy link
Contributor

cool

@pannous
Copy link

pannous commented Oct 12, 2020

Why is this closed? We still can't delete individual functions, can we?

I don't want to restart the whole thing just because I mis-defined one function.

@timholy
Copy link
Member

timholy commented Oct 12, 2020

It was fixed in 0.3 but problematic so removed before 1.0. No one reopened the issue, perhaps because there may be a more appropriate one already open? (I have not searched.)

We do have Base.delete_method, and Revise will handle deletions automatically for you. But that doesn't work if you wanted that name to not be a function.

@pannous
Copy link

pannous commented Oct 12, 2020

Thanks, that's what I had been looking for
delete(func)=Base.delete_method(@which func)

@ptoche
Copy link
Contributor

ptoche commented Apr 10, 2021

In atom/juno is exit() the way to restart a session without closing atom?

@jankap
Copy link

jankap commented Apr 14, 2021

Can it be reopened? :)

@oscardssmith oscardssmith removed this from the 0.7 milestone Apr 14, 2021
@oscardssmith
Copy link
Member

I'm re-opening, despite personally thinking that this is probably a bad thing to have.

@oscardssmith oscardssmith reopened this Apr 14, 2021
@jankap
Copy link

jankap commented Apr 15, 2021 via email

@KristofferC
Copy link
Member

The old strategy of "redefining" Main should now work much better because packages are not loaded directly into Main but into another hidden module.

@jankap
Copy link

jankap commented Apr 15, 2021

@KristofferC , is this still working or is that an idea how to tackle this ticket?

Thanks

@rajeee
Copy link

rajeee commented Jun 29, 2022

It's been quite some time. Is there any way to remove variables (especially functions) from current session without having to restart the kernel?

@StefanKarpinski
Copy link
Member

Now that we can activate a different module than Main, it might be possible to create a new Main module and replace the old one with the new one. It could further be possible to copy some of the old bindings over, which would allow emulating the deletion of the non-copied bindings.

@tgross35
Copy link

Just to add a specific use case - this is pretty brutal for jupyter notebooks. It's not uncommon to have something simple like:

using Plots

x = 10
plot(...)

If you wanted to change x to x(t) = 10 * t, your only option is to restart the kernel - same if you need to change it back later. Now of course it would be nice if restarting the kernel and loading plots was faster out of the box, but I don't think it really needs to be when a call to clear() at the beginning of the cell could be significantly faster. I don't think the suggested workaround in the docs is very good when it requires modules for even the most simple program like this.

It seems like there was some opposition to adding a clear() function at some point - anyone know why? I can't seem to find if it was a technical limitation (seems like that was at least part of it), or if there was some subjective reason. The other discussions seem to point to a mailing list - but somewhat unhelpfully, there are no links and it seems like the list may no longer be in existence.

@vtjnash
Copy link
Member

vtjnash commented Feb 11, 2023

Eventually we said this should be implemented by the interactive package (eg juypter), to manage Modules and allow you to get a new one whenever and however you want, instead of providing a single behavior in Base.

@vtjnash vtjnash closed this as completed Feb 11, 2023
@vtjnash
Copy link
Member

vtjnash commented Feb 11, 2023

x = t->10t

Also would work for your case

@tgross35
Copy link

Thanks for the tip about workaround syntax.

Do you mind clarifying the reason you don't think this would be reasonable in base? Coming from Matlab or R, it's very handy to be able to remove specific variables from scope in REPL without needing module workarounds.

@vtjnash
Copy link
Member

vtjnash commented Feb 11, 2023

Yeah, we are still considering if we could let Revise.jl delete variables, but currently it is a major reason Julia is fast so it is a bit tricky to change

@StefanKarpinski
Copy link
Member

The thing we could do at this point is create a new Main module, make it the new active REPL module, and then throw out the old Main module. That would have the desired effect (mostly). We now have the ability to replace the active REPL module, so this might be much easier to do now than in the past.

@vtjnash
Copy link
Member

vtjnash commented Feb 13, 2023

Right. Notably though that must be implemented in REPL / IJulia / etc. now, since they have the capability of giving the user a new module, but Julia base cannot force them to implement it

@StefanKarpinski
Copy link
Member

Yes; that distinction is probably not especially clear to some readers who think of Base as "everything that comes with Julia by default". But yes, this would be a REPL feature, not a Base language feature. There would be no way to clear variables from a Julia script, for example (except to make yourself a new module and continue evaluation there).

@gwd666
Copy link

gwd666 commented Nov 30, 2023

btw afaict abstract classes behave the same way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

No branches or pull requests