Dump previously created procedures in Scheme / Emacs
Posted by shapingthefuture@reddit | learnprogramming | View on Reddit | 4 comments
I'm currently working through SICP, which has you doing Scheme. I've only used VS Code in the past, but I'm fighting my way through Emacs for this. But I'm running into something that seems incredibly strange to me and I'm not finding any solutions from various attempts to Google this question. I suspect I'm using the wrong terms.
At one point, the book has you define a function for doing absolute value, defined with the name abs. Now, I would expect that if you remove that function definition from your file, it should stop working, because it's no longer defined.
Instead, it just keeps working in the REPL window, and I'm completely baffled as to why and how to reset my (sorry, I may not know the right term here) global scope.
Things I have tried so far:
1) Making sure my scheme file is completely empty, including opening it with a plain text editor in a new window to make 100% sure that it really is empty.
2) Closing both the file and the REPL and re-opening the REPL.
3) Completely exiting emacs and restarting it.
Dazzling_Music_2411@reddit
You don't say which Scheme you are using with emacs.
Emacs is a hugely configurable beast, and a lot depends on how it is set up.
For instance, I use MIT-Scheme, but just because I may have a file open in a buffer, it doesn't mean it's loaded into Scheme. There are commands for doing so explicitly.
The commonest, during development, I find, is to use C-x C-e after writing a function, in order to load it up for use. Obviously there are also commands for loading whole files, code regions, etc.
BTW, how did you set Scheme up? Did you use
M-x run-scheme
which uses the default scheme in your system?
shapingthefuture@reddit (OP)
Sorry about that, still new enough to this particular area that I don't know all the things I should include. It's MIT-Scheme, and I haven't customized Emacs at all so far. The version I have installed is GNU Emacs 29.3.
I'm on Linux, and I installed scheme originally with
Then I'm launching it by starting Emacs from terminal with the emacs command.
In Emacs, I'm launching Scheme with
I basically just followed the instructions here to set it up.
But I also see where I went wrong. I misunderstood and thought that once the REPL was open, that opening a file with C-x C-f would pull whatever I did to it in. Which I think it must under certain conditions because I was able to write my functions that aren't built in and run them just fine.
Thank you for the advice on C-x C-e; I will give that a go from here on!
Dazzling_Music_2411@reddit
Ah, OK cool, similar setup, then.
Now, the way I like to develop, is to have two wndows side by side. The first one runs MIT-Scheme and the REPL, just as you are doing. I use C-x 2 or C-x 3 to open another window. This is the window you will develop in, and also dispatch functions to the REPL from. If you issue the commands M-x interactive and M-x scheme-mode, it will also format nicely for you, do syntax highlightiing, and populate the menu with useful commands like load function, load buffer, etc, etc.
You can also automate the script so does it all this at start time, and also pre-load any useful functions that are not in MIT-Scheme by default. I just described how to do it manually, but emacs is all about experimenting and configuring it how you like..
shapingthefuture@reddit (OP)
Got it--thank you for the advice!