我正在使用 emacs org 模式进行可重复的研究。我无法将调用结果链接到代码块。作为我正在尝试做的一个最小示例:
* Functions
#+name: f1
#+begin_src elisp :var x=7
(+ x x)
#+end_src
#+name: f2
#+begin_src elisp :var x=7
(+ x 2)
#+end_src
* Data
#+name: intermediate
#+call: f1(x=5)
#+RESULTS: intermediate
: 10
#+call: f2(x=intermediate)
当我调用
f2
,它失败了,因为 x
是 nil
.如果我从 f1
上的通话中删除姓名,然后 f2 工作,但如果我更改 f1
的参数,结果不会保持同步.如何告诉 org 模式我想查看函数调用的结果,而无需在每次计算结果时手动重命名?
最佳答案
您可以使用Noweb 来实现您想要的。 Data
下计算中的引用语法标题:
* Functions
...
* Data
#+name: intermediate
#+BEGIN_SRC elisp :noweb yes
<<f1(x=5)>>
#+END_SRC
#+BEGIN_SRC elisp :noweb yes
<<f2(x=intermediate)>>
#+END_SRC
来自 manual (强调我的):
The "noweb" ... Literate Programming system allows named blocks of code to be referenced by using the familiar Noweb syntax:
<<code-block-name>>
When a code block is tangled or evaluated, whether or not "noweb" references are expanded depends upon the value of the
:noweb
header argument. If:noweb
yes, then a Noweb reference is expanded before evaluation. [...]It is possible to include the results of a code block rather than the body. This is done by appending parentheses to the code block name which may optionally contain arguments to the code block as shown below.
<<code-block-name(optional arguments)>>
通过此设置,您可以更改
x
的值你要传递给 f1
并成功重新导出/重新评估,而无需修改其他任何内容。
关于emacs - 如何在 emacs org 文件中引用调用 block 的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24144961/