简体   繁体   中英

How To Run Scheme in Mac Emacs? - “process scheme exited abnormally with code 1 / 126”

Questions with similar titles (linked) do not cover the specific errors I am encountering, hence the new ask.

Context:

I am trying to set up an environment for working with scheme in emacs so I can work through the SICP book. I understand it is possible to integrate the two nicely so they work well together. I understand there are many ways of doing this even with extra features (I've seen the names quack/racket ...) but those seem like the more advanced options. Since I am having trouble setting up this bare basics 'run-scheme' in emacs I have not looked into these options extensively.


Where I'm at / What I've tried:


  1. I downloaded MIT:GNU scheme 9.2 for OS X (x86-64). This works as expected and I can run the interpreter either from the terminal with:

     $ scheme 

    or by executing the file "/Applications/MIT:GNU Scheme.app/Contents/Resources/mit-scheme" (which opens the interpreter in a new terminal window).

    At this point Mx run-scheme returns a message saying that no such file or directory exists.

    I read these two questions for reference and then:


  2. I created a symbolic link to the binary/exec file "/Applications/MIT:GNU Scheme.app/Contents/Resources/mit-scheme" (which works perfectly when executed from finder/the terminal), then placed this file in "/usr/bin" with name "scheme".

    At this point Mx run-scheme returns:

     /usr/local/Cellar/emacs/24.5/Emacs.app/Contents/MacOS/Emacs:/usr/bin/scheme: Exec format error Process scheme exited abnormally with code 126 

  3. The symlink file looked very out of place in the bin folder so not knowing what else to try I removed the symlink and instead created an actual copy of the mit-scheme exec file and placed that in "/usr/bin".

    Mx run-scheme now returns this:

     /usr/bin/scheme: can't find a readable default for option --band. searched for file all.com in these directories: /Applications/mit-scheme.app/Contents/Resources Inconsistency detected. Process scheme exited abnormally with code 1 

Searching for help with understanding these error messages lead me to threads about issues with setting up scheme on windows OS, which is confusing, and I feel I am now out of my depth - hoping someone knows where I'm going wrong.

End

It seems strange because I know that the 'Mx run-scheme' command is trying to access the location "/usr/bin/scheme" and I have made sure that such a location exists, and that the scheme exec file at that location works properly - I don't understand what other requirements emacs has for this to work.

What is the run-scheme command actually doing? What other requirements does it have to function as expected?

MIT Scheme looks for its libraries (including its 'bands') in a location derived from the executable's path. If the libraries are in a non-standard location, then the mit-scheme executable won't find them.

For example, in my setup, MIT scheme is located at: /usr/local/scheme/bin/mit-scheme and the band, and other stuff, is located at /usr/local/scheme/lib/mit-scheme/ .

For Emacs I've defined:

(defun mit-scheme () 
  (interactive)
  (run-scheme "/usr/local/scheme/bin/mit-scheme -library /usr/local/scheme/lib/mit-scheme")) 

Which ensures mit-scheme can find its library when, in Emacs, I perform Mx mit-scheme . If I want MIT Scheme to be the default, I would use:

(setq scheme-program-name "/usr/local/scheme/bin/mit-scheme -library /usr/local/scheme/lib/mit-scheme")

You'll need to set your values according to your installation. You also might have an option of setting MIT Scheme related environment variables to point to your library location. The relevent one is MITSCHEME_LIBRARY_PATH.

$ mit-scheme --help
Usage: mit-scheme --OPTION ARG ... --OPTION ARG ...

This machine accepts the following command-line options.  The options
may appear in any order, but they must all appear before any options
for the band.

--library PATH
  Sets the library search path to PATH.  This is a colon-separated
  list of directories that is searched to find various library files,
  such as bands.  If this option is not given, the value of the
  environment variable MITSCHEME_LIBRARY_PATH is used; if that isn't
  defined, "/usr/local/lib/mit-scheme" is used.

--band FILENAME
  Specifies the initial band to be loaded.  Searches for FILENAME in
  the working directory and the library directories, returning the
  full pathname of the first readable file of that name.  If this
  option isn't given, the filename is the value of the environment
  variable MITSCHEME_BAND, or if that isn't defined, "runtime.com"; in
  these cases the library directories are searched, but not the
  working directory.

...

I'm also trying to play with the materials from SICP. It took a couple of hours and attempts to get things working.

I realized my paths were wrong after following Don't Panic! on Mojave (macOS 10.14).

I installed mit-scheme 10.1.5 from source running the installation steps from here and in the readme. My paths were different, which caused the --band command to fail.

If you're having issues double check all your paths are what you expect.

I used make install with default paths to install to /usr/local/bin and /usr/local/lib

Mac comes with emacs 22.1.1, which is old, but it works with the extra scripts from the professor for customizing emacs.

NOTE: If you quit emacs 22.1.1, it doesn't warn you about stopping scheme , which will lead to a 100% CPU usage process that you can't stop without Activity Monitor. Newer versions of emacs will prompt you to quit the scheme process before exiting (there may be a setting for older versions as well).

I installed emacs 26.1 using Homebrew and was able to get everything running after fixing these issues:

There is an error on newer versions of emacs (24+?) with ad-advised-definition-p , fix it by commenting out the function in "multi-term.el" around line 334:

; (defcustom multi-term-dedicated-skip-other-window-p nil
;   "Default, can have `other-window' select window in cyclic ordering of windows.
; In cases you don't want to select `multi-term' dedicated window, use `other-window'
; and make `multi-term' dedicated window as a viewable sidebar.
;
; So please turn on this option if you want to skip `multi-term' dedicated window with `other-window'.
;
; Default is nil."
;   :type 'boolean
;   :set (lambda (symbol value)
;          (set symbol value)
;          (when (ad-advised-definition-p 'other-window)
;            (multi-term-dedicated-handle-other-window-advice value)))
;   :group 'multi-term)

Path setup

I had a warning:

Warning (initialization): Your ‘load-path’ seems to contain
your ‘.emacs.d’ directory: ~/.emacs.d
This is likely to cause problems...
Consider using a subdirectory instead, e.g.: /Users/paulsolt/.emacs.d/lisp

Which I solved by pointing the top line of the ~/.emacs file to:

;; (setq load-path (append (list "~/.emacs.d") load-path))
(setq load-path (append (list "/Users/paulsolt/.emacs.d/config") load-path))

The config folder already had all the scripts, that I think I was having issues getting Emacs to see.

I installed scheme from source without modifying install paths, so I changed this line:

;; This is the place where you have installed scheme. Be sure to set
;; this to an appropriate value!!!
;;(setq scheme-root "/mit/6.945")
(setq scheme-root "/usr/local")

Next to fix the issue that was causing --band to fail I modified this line.

(setq scheme-program-name
      (concat
       scheme-root "/bin/mit-scheme "
       "--library " scheme-root "/lib/mit-scheme-c "
       ;;"--band " scheme-root "/lib/mit-scheme-c/all.com "
       "--band " scheme-root "/lib/mit-scheme-x86-64/all.com "     
       "-heap 10000"))

My scheme library was installed in a mit-scheme-x86-64 folder.

Lastly, it appears that there's some other commands I had to comment out, since they don't seem to exist ...

;;(tool-bar-mode -1)
;;(scroll-bar-mode -1)

After all that setup I'm now able to create a scheme script in emacs, and I can run the script using the meta key (iTerm set my Alt key to Esc+):

M-x run-scheme

Tip: Being newer to emacs, I'm working through the emacs tutorial (Ch t) which is essential if you're going the text-based approach. In college I used emacs outside of terminal, but I'm giving it go inside the terminal this time to learn more hotkeys.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM