所以,我使用scribble/lp模块使用plt-scheme编写我的第一个文字程序:
#lang scribble/lp
(require scribble/lp)
<<lp_scheme.ss>>
@chunk[<squarefunction>
(define (f x)
(* x x))]
Run Code Online (Sandbox Code Playgroud)
当然没有什么有用的.现在我有点想知道为什么我不会使用简单的注释,而不是文字编程结构.任何意见欢迎.如果有人可能有更多的曝光/曝光,那将是非常好的.有了它可能会更直观地解释良好记录的代码和使用Literate编程结构编写的代码之间的差异.
我正在尝试做这样的事情:
* Define some functions
#+begin_src python :noweb_ref defs
def f1(a,b,c):
return True
def f2(d,e,f):
return False
#+end_src
* Use them in a results-exported block later
#+begin_src python :results output :exports both :tangle yes
<<defs>>
print "test results:"
print f1(1,2,3)
#end_src
Run Code Online (Sandbox Code Playgroud)
我想要发生的是,当评估块以产生导出输出时,<< defs >>将被扩展为纠结样式.实际发生的是<< defs >>按字面意思进行评估并导致语法错误.
当这样的拼接块输出到输出文件时,一切都运行得很好,但是当我导出缓冲区时,我无法弄清楚如何做同样的事情.
建议?
emacs literate-programming org-mode org-babel reproducible-research
我正在一个.lhs文件中编写一个程序,其中包含Haskell中的代码(我正在指定这个,因为我希望它清楚地表明它不仅用于渲染pdf,而且还用于使用runhaskell或ghci执行).我正在使用如下的lstlisting呈现代码:
\begin{lstlisting}
> Haskell code here
\end{lstlisting}
Run Code Online (Sandbox Code Playgroud)
无论如何,代码本身需要一些我必须导入的模块,但我不希望导入出现在生成的pdf中.所以,我试图把代码放在没有lstlisting块的地方,如下所示:
> import X
> import Y
...
Run Code Online (Sandbox Code Playgroud)
但它不起作用,生成的PDF只会使这些行不像代码一样lstlisting.如何编写导入代码只是为了执行而不是在PDF本身中显示,我该怎么办?
当用Org-Babel编写有文化的Python时,我需要能够控制缩进级别(显式地:indentation-level 3或隐式地使用一些聪明的指示).
这是一个演示此问题的示例文件.
#+BEGIN_SRC python :tangle "sample.py"
class Test:
def __init__(self):
self.a = 'a test class'
#+END_SRC
#+BEGIN_SRC python :tangle "sample.py"
def say_hi(self):
print 'Hi from this Test object!'
print 'ID: {}'.format(repr(self))
print 'Data: {}'.format(str(self.__dict__))
#+END_SRC
Run Code Online (Sandbox Code Playgroud) 我正在审查一篇科学论文,裁判要求我的R代码作为Sweave文件提供.我以前从未听说过Sweave,你知道什么是更好的方法吗?
非常感谢 :-)
我正在以组织模式开发一个有文化的程序.我在.emacs中有几个函数用于为程序设置repl,是否可以将这些函数移动到org-mode文件,并且每次打开文件时都会对它们进行评估(比如缓冲区本地变量,但是功能.)
我正在尝试在Graham Hutton的Haskell编程书(http://www.cs.nott.ac.uk/~gmh/book.html)中执行示例.尽管这些例子都是有文化的haskell,但我可以启动ghci来加载示例; 例如ghci cipher.lhs(http://www.cs.nott.ac.uk/~gmh/cipher.lhs):
GHCi, version 7.10.2: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( cipher.lhs, interpreted )
Ok, modules loaded: Main.
*Main> let2int 'a'
0
Run Code Online (Sandbox Code Playgroud)
但是有一些例子,由于ghci的变化,我有一些问题; 例如在第8章的Parsing.ls中,我有No instance for (Applicative ...)错误.
从https://ghc.haskell.org/trac/ghc/wiki/Migration/7.10我得到了一些提示,通过添加一些代码来消除一些错误.
> instance Applicative Parser where
> pure = return
> (<*>) = ap -- defined in Control.Monad
>
> instance Functor Parser where
> fmap = liftM
>
> instance Alternative Parser where
> (<|>) …Run Code Online (Sandbox Code Playgroud) 我是matlab的初学者.现在我想要一个循环,这样它就可以迭代一个向量(不是连续的数字),它通过迭代包含数量减少的元素.
例如,我[1; 2 ;3; 4](将其视为1,2,3,4号人物)然后我想做一些事情,例如第1和第4人获得食物,第2和第3人没有食物.
在下一轮中,我希望第2和第3人(未分配的人)再次完成分配过程但不是1和4.所以我创建了一个向量[2; 3]以跟踪那些没有食物的人.
然而,for i=1:length(vector)给我一系列连续的数字,我想要的是
for i in vector do something; end
怎么实现这个?
当我刚刚放
i=vector,
Run Code Online (Sandbox Code Playgroud)
Matlab说Index超过了矩阵维度
我们希望完全从组织模式的babel文件中自动生成Leiningen项目树.我们希望这样做,以便我们也可以通过创建漂亮的排版文档
org-latex-export-to-pdf.我们希望在org-mode中使用Clojure中的完整文字编程.
以下命令:
$ lein new ex1
Run Code Online (Sandbox Code Playgroud)
生成一个如下所示的树:
ex1
ex1/.gitignore
ex1/doc
ex1/doc/intro.md
ex1/project.clj
ex1/README.md
ex1/resources
ex1/src
ex1/src/ex1
ex1/src/ex1/core.clj
ex1/test
ex1/test/ex1
ex1/test/ex1/core_test.clj
Run Code Online (Sandbox Code Playgroud)
我们想通过org-babel-tangle在emacs中的org-mode缓冲区中运行而不再执行相同
的操作.
一个难题出现了:而tangle高兴地产生像现有的子目录中的文件src和test,似乎不愿意生产子目录,如果它们不存在.这意味着我们必须通过其他方式创建目录结构 - 除非我们能够tangle为我们做到这一点,这就是StackOverflow问题的主题
.
目录结构中有六个文件Leiningen.我可以将它们全部删除,然后BEGIN_SRC使用以下块来从我的org文件重新创建它们
#+BEGIN_SRC clojure :tangle ./ex1/src/ex1/core.clj
(ns ex1.core)
(defn foo
"I don't do a whole lot."
[x]
(println x "Hello, World!"))
#+END_SRC
Run Code Online (Sandbox Code Playgroud)
特别注意子目录路径的名称
#+BEGIN_SRC clojure :tangle ./ex1/src/ex1/core.clj
Run Code Online (Sandbox Code Playgroud)
如果我们的目录结构已经存在,一切都很好.org-mode tangle将创建或更新上述所有六个文件,并在任何现有目录中创建新文件.我们不知道如何tangle制作目录; 它抱怨说没有这样的目录.
如果您想了解更多详细信息,.org可在此处 …
我已经冒险尝试并准备使用 bookdown 完全在 RStudio 中出版的手稿。在正文中,我想在单独的支持信息 .Rmd 文件中交叉引用数字。
假设这是我的主要文本文件,名为main.Rmd:
---
title: "Main text"
output:
bookdown::pdf_book:
toc: no
---
Here is the main text file. I would like to refer to \@ref(fig:supporting-figure).
Run Code Online (Sandbox Code Playgroud)
这是名为 的支持文本supporting.Rmd和要参考的图,保存在同一文件夹中:
---
title: "Supporting info"
output:
bookdown::pdf_book:
toc: no
---
Here is the supporting text.
```{r supporting-figure}
plot(cars)
```
Run Code Online (Sandbox Code Playgroud)
如何supporting-figure在正文中交叉引用?
我已经检查了 Yihui's bookdown manual 中有关交叉引用的部分,但我看不出如何将其扩展到文件之间的交叉引用。
我还发现了这个问题: Cross-reference figure in a separate Rmarkdown (PDF) file 但接受的答案对我不起作用(也许是因为我使用的是 bookdown 而不是 base Rmarkdown?)
我试图在C#中创建一个简单的数组示例,它遍历数组,只显示大于或等于2但小于4的值.
在if语句中,我不确定如何在迭代函数中最好地形成两部分语句.这是我的例子,它显然没有做任何事情:else if(array [i]> = 2 array [i] <4)
我想要创建的完整代码:
int[] array = new int[5];
array[0] = 1;
array[1] = 2;
array[2] = 3;
array[3] = 4;
array[4] = 5;
for (int i = 0; i < array.Length; i++)
{
if (array[i] >= 4)
{
Console.WriteLine(array[i]);
}
else if (array[i] >= 2 array[i] <4)
{
Console.WriteLine(array[i]);
}
else
{}
}
Console.ReadKey();
Run Code Online (Sandbox Code Playgroud)
寻找有关如何最好地创建此功能的建议.