emacs - 如何区分 org-babel 代码块中的方案方言?

标签 emacs racket org-mode

评估此代码(C-c C-c):

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

导致以下 babel 错误:

ERROR: Unbound variable: andmap

原因:babel 使用 Guile 而不是 Racket 评估代码。我如何告诉 Babel 使用 Racket 而不是 Guile 执行代码?

最佳答案

http://terohasu.net/blog/2011-09-08-on-racket-support-in-emacs-org-mode.html介绍一种方法:

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.

关于emacs - 如何区分 org-babel 代码块中的方案方言?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9338255/

相关文章:

github - 如何使用 org-mode 在 github 上创建个人 wiki+博客?

css-mode 从 Emacs 中的前缀属性中删除破折号

c - 是否可以使用 C 为 GNU Emacs 编写自定义原语?

etags 中的 Javascript 支持

scheme - 如何使用 DrRacket 创建和保存文件扩展名为 .scm 的 Scheme 程序?

scheme - Racket 宏语法匹配方括号

matlab - 如何在组织模式下在同一文件中定义matlab函数

linux - 在 Emacs 中取消绑定(bind) C-d 和删除

racket - 是什么让我的图像看起来只有预期宽度的一半?

haskell - 如何使用 Stack 为 Haskell 设置 org-babel