How to run scheme with Emacs?
Asked Answered
Q

3

23

I followed this tutorial and successfully installed Emacs, STk, Quack.

The question is how can I load my program like I do in Racket?

In Racket I can edit my code in the upper window, type some codes, save and run. Then the lower window will automatically loaded the code I just wrote. Then I can play with it.

I've tried M-x run-scheme. It only brings me into type mit-scheme. Then it says No such file or directory exists. Then I tried F5 (The author from the site wrote a .emacs file enables me to press F5). Then the STk opens up. I can load my scheme file in STk. But it will brings me back to MIT Scheme with edwin.

I want to have the same thing in Racket (Write/REPL). But more flexibility with the key movement. In Racket you don't have C-f C-n C-a...etc.

Could anyone teach me how to do so?

Quartile answered 23/11, 2010 at 19:21 Comment(2)
Not an answer to your question, but: Racket is very different from STk. One particular aspect of this is more relevant to your question -- in STk you use load to load files, since there is no module system (at least none that I know of).Where
Thanks for your response. I only want to use STk (or any implementations) as an interior compiler inside Emacs to compile my code. Anyway, thanks!!! :DQuartile
Y
31

I literally just set this up on my Macbook. Since you didn't specify what system you are on, I will hope you're using some Unix flavor... I'm not familiar with STk really, but this might help you sort out whatever issues you are having, which sound really similar to the problems I faced.

If you install a Scheme implementation (I am using MIT Scheme, edited to add that this also works with Racket, using mzscheme) it may come with a symlink named "scheme" - this is what Emacs looks for, I think.

If it doesn't (MIT Scheme doesn't seem to on OS X) you can edit your Emacs configuration, in Emacs type M-x customize-group then type scheme. Scroll down a bit and find the Scheme program name field. Change it to your Scheme implementation command, like mit-scheme or mzscheme. You can also just create a symlink in your PATH which points to the right binary:

sudo ln -s /Applications/mit-scheme.app/Contents/Resources/mit-scheme
    /usr/local/bin/scheme

For MIT Scheme, you also need to set the MITSCHEME-LIBRARY-PATH variable, so add this to your .emacs.

(setenv "MITSCHEME_LIBRARY_PATH"
    "/Applications/mit-scheme.app/Contents/Resources")

Then you should be able to start an inferior Scheme buffer with M-x run-scheme. And pass code to the REPL with C-x C-e, which evaluates the expression before the point.

If this doesn't work (it didn't for me) you may need to make sure that the path Emacs uses for executing shell commands includes the scheme symlink or whatever directory contains the binary for your implementation. With some experimentation, I fixed this by adding this to my .emacs file:

Emacs is ignoring my path when it runs a compile command

For references, the other SO question which I used to set this up:

How do I get a scheme interpreter working inside Emacs?

Yezd answered 23/11, 2010 at 20:55 Comment(6)
Sorry I did not mention my system is windows. I will try your method. Thanks a lot!!!! Good day!Quartile
Sorry if it doesn't work on Windows. According to the MIT Scheme site the xscheme.el interface library isn't compatible with non-Unix systems, but I don't know if the basic C-x C-e send-to-REPL works. Report back!Yezd
@Joe On my Emacs (23.2.1 on OS X) C-c C-e doesn't really work: All alone it doesn't send the preceding expression to the REPL. However if I follow it with C-x C-e it sends whatever expression that preceded the point when I did C-c C-e and then send the expression currently under the point. Can you shed any light on this?Yezd
Ah, I've figured it out, C-c C-e sends the last definition, whereas C-x C-e sends the last S-exp.Deidradeidre
+1 for the pointer to M-x customize-group for scheme, I put in the path to my mit-scheme and after exiting and restarting emacs M-x run-scheme worked great!Assumed
I'd just like to mention that you can skip the scheme-program-name configuration altogether with a prefix: C-u M-x run-scheme and it will prompt for one. Handy if you've got multiple lying around (csi, gsi, chibi-scheme and even ssh host scheme).Novocaine
S
3

The 64-bit download from GNU now has the .app named as "MIT:GNU Scheme.app." I tried @spacemanaki's instructions but I kept getting:

bash-3.2$ export MITSCHEME_LIBRARY_PATH=/Applications/MIT:GNU\ Scheme.app/Contents/Resources
bash-3.2$ scheme
    scheme: can't find a readable default for option --band.
    searched for file all.com in these directories:
    /Applications/MIT
    /Applications/MIT:GNU Scheme.app/Contents/Resources/GNU Scheme.app/Contents/Resources

Eventually I realized the semicolon was acting as a path separator. So just make sure you rename it:

mv MIT:GNU\ Scheme.app/ mit-scheme.app

Then the above instructions will work fine - although you may have to use Finder to do the rename, because when I did it on the shell my Resources folder disappeared.

Stonechat answered 12/2, 2013 at 3:43 Comment(1)
Thank you so much. I had no idea what was causing that error messageZygophyllaceous
I
3

I would recommend to use Homebrew to install the mit-scheme with simple command brew install mit-scheme if your are on a Mac. Find your ~/.emacs file, if it not exists then create one, append this to the end of the file:

(setq scheme-program-name  "your/mit-scheme/path")

Use which mit-scheme command to find out where your mit-scheme was installed. Take my MacOS X as an example:

(seq scheme-program-name   "/usr/local/bin/mit-scheme")

Save it and quit. Then restart your Emacs and type M+x and you are in the mit-sheme.

Inunction answered 21/10, 2014 at 11:9 Comment(1)
(setq scheme-program-name "/usr/local/bin/mit-scheme") ;; novice baffling typo!Kinsley

© 2022 - 2024 — McMap. All rights reserved.