How can I distinguish scheme dialects in org-babel code blocks?

余生长醉 提交于 2020-01-04 05:24:13

问题


Evaluating this code (C-c C-c):

#+begin_src scheme
(andmap + '(1 2 3) '(4 5 6))
#+end_src

leads to the following babel error:

ERROR: Unbound variable: andmap

The cause: babel evaluated the code with Guile instead of Racket. How can I tell Babel to execute code using Racket, not Guile?


回答1:


http://terohasu.net/blog/2011-09-08-on-racket-support-in-emacs-org-mode.html describes a way:

When configuring Emacs to set things up I wasn’t familiar with Babel or any of the solutions for evaluating Scheme code under Emacs for that matter. After some looking at Babel and Inferior Lisp, I didn’t manage to configure Babel to invoke Racket for evaluating a code listing. Instead I resorted to replacing the Babel code for Scheme support (in the ob-scheme.el) with basically just the following code:

(defun org-babel-execute:scheme (body params)
  (let* ((tangle (cdr (assoc :tangle params)))
         (script-file 
          (if (string-equal tangle "no")
              (org-babel-temp-file "org-babel-" ".rkt")
            tangle)))
    (with-temp-file script-file
      (insert body))
    (let* ((pn (org-babel-process-file-name script-file))
           (cmd (format "racket -u %s" pn)))
      (message cmd)
      (shell-command-to-string cmd)
      )))

This solution creates a new Racket instance for every evaluation, and hence is not as efficient as an Inferior Lisp based solution (or similar), but it works, is more straightforward, avoids Racket issues such as specifying the correct module context for evaluating the code, and the evaluation context is always “clean” as a new Racket instance is used.



来源:https://stackoverflow.com/questions/9338255/how-can-i-distinguish-scheme-dialects-in-org-babel-code-blocks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!