Is user environment reset possible in REPL schema?

New question -

Is there a way for me to reset my current REPL environment (i.e. the default user environment) without exiting and reloading my REPL? Basically, I need a way to destroy the current environment so that none of my previous definitions work. This uses the GNU / MIT scheme.

If this is not possible, what is the best thing to do when just messing with the code in the REPL? I heard people talking about creating and removing packages, but most of the examples seem to be for Common Lisp, which is slightly different.

I found information on how to do this in the Clojure REPL, but there were reservations, and it seems that this is Clojure-specific: Can I clear the replica?

Thanks!

Edit: I can do the same functionally, leaving and restarting the REPL process itself. I found a way to do this, but keep in touch with my editor (vim) using vim-screen. This is an acceptable solution if there is no way to do this from the REPL. However, I will keep the question open longer to find out if there is a way to do this inside the language, as I think it will be instructive.

+6
source share
1 answer

I think this is implementation specific, but in MIT Scheme you can clear REPL environment with

1 ]=> (ge (make-top-level-environment)) 

Function (ge [environment]) "Changes the current environment of the REP loop to [environment]." and the make-top-level-environment function "returns the newly selected make-top-level-environment ."

MIT Scheme has many environmental management features that you can view here.

I tested this on Mac OS X (10.6.7) using MIT Scheme 9.0.1 installed via a prebuilt binary from the GNU site, with the following REPL session:

 1 ]=> (define foo 1) ;Value: foo 1 ]=> foo ;Value: 1 1 ]=> (ge (make-top-level-environment)) ;Value 13: #[environment 13] 1 ]=> foo ;Unbound variable: foo ;To continue, call RESTART with an option number: ; (RESTART 3) => Specify a value to use instead of foo. ; (RESTART 2) => Define foo to a given value. ; (RESTART 1) => Return to read-eval-print level 1. 2 error> 

I think different implementations have different conventions, but I don’t think that something is very similar to Common Lisp. If you are not tied to the MIT Scheme, you should check out Racket and Dr Racket, which is a good IDE that can be more powerful than a simple REPL on the command line, and I think it has some kind of modular system. A racket is your own dialect of the Scheme, so depending on what you do, it may not be practical. (the default language module in Racket is not the same as the MIT scheme)

I struggled with all this recently (the last few months) when I went looking for a scheme that could run code from Lisp in Small Pieces that has a bunch of weird macros. Gambit was the best choice. If you do not have such a need, check out Racket.

+11
source

Source: https://habr.com/ru/post/895114/


All Articles