如何区分组织架构代码块中的方案方言? [英] How can I distinguish scheme dialects in org-babel code blocks?

查看:145
本文介绍了如何区分组织架构代码块中的方案方言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

评估此代码(Cc Cc):

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

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

导致以下babel错误:

leads to the following babel error:

ERROR: Unbound variable: andmap

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

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

推荐答案

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


配置Emacs设置内容时我不熟悉Babel
或任何解决方案,用于评估Emacs下的计划代码
。在看了Babel和 Inferior
Lisp

我没有设置配置Babel来调用Racket来评估
代码列表。相反,我用基本上只有以下
代码替换了
计划支持的Babel代码:

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)
      )))

此解决方案为每个评估创建一个新的Racket实例,因此
不如基于Lisp的解决方案(或
类似),但它的工作原理比较简单,避免了Racket问题
,如指定用于评估代码的正确的模块上下文
和评估上下文始终是干净的,因为使用了新的Racket实例

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.

这篇关于如何区分组织架构代码块中的方案方言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆