- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我在 emacs 中从 Swank repl 运行 Clojure 代码时,主线程将使用 printf 将消息打印到 repl。但是,如果我运行代理或显式创建也打印的其他线程,有时输出不会显示,有时它会显示在我正在运行 Swank 的控制台窗口中。我很想知道为什么。
编辑:感谢丹尼尔在下面的回答,我现在知道其他线程没有绑定(bind)到 REPL 的输出。此代码有效,因为您从运行的地方传入 out。然而我的新问题是,这段代码现在每个线程都阻塞,所以它不是并行运行,而是一次运行每个线程,所以我需要一个更能感知线程的输出方法。
(defn sleeper-thread [out id t]
"Sleep for time T ms"
(binding [*out* out]
(printf "%d sleeping for time %d\n" id t)
(Thread/sleep t)
(printf "%d slept\n" id)))
(defn test-threads [n out]
(dotimes [x n]
(.start (Thread. (#(sleeper-thread %1 %2 %3) out x (+ 2000 (rand-int 5000)))))))
最佳答案
原因是,在其他线程 *out*
不绑定(bind)到 REPL 的流。尝试这样的事情:
(let [repl-out *out*]
(defn foo []
(binding [*out* repl-out]
...)))
foo
来自另一个线程,
*out*
将绑定(bind)到您定义函数时的任何内容(即 SLIME REPL),因此打印将按预期工作。
(defmacro future-output [& body]
`(let [out# *out*]
(future
(binding [*out* out#]
~@body))))
- code path for using vars is now much faster for the common case, and you must explicitly ask for :dynamic bindability
关于multithreading - 使用 swank/slime 理解 Clojure 中的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4532862/
我宁愿不必手动为每一行添加分号。 规范: Aquamacs 2.1 (Emacs 23.2) 史莱姆 2010-11-16 MacPorts CLISP 2.49 Mac OS X 10.6.4 Ma
我正在尝试使用 asdf 创建一个名为“a”(学习)的基本包,我已经在 package.lisp 中定义了该包,我的主文件 a.lisp 开头为: (in-package :a) ... 如果我正在开
我有 sbcl 在 emacs 24.1 中工作的 slime,但无法打开 slime repl。 我可以使用 M-x slime 连接到 inferior-lisp 缓冲区中的 sbcl,但我无法调
我在短时间内使用 emacs 和 lisp(使用 slime)...这个工作正常,但是今天当我运行它时出现以下消息: eval-buffer:Symbol 的函数定义为 void:define-sli
我为 clojure 和普通 lisp 设置了 emacs,但我还想要 (slime-setup '(slime-fancy)) 用于普通 lisp。如果我将该行添加到 init.el,clojure
我目前处于模式:C-x 2 通常,我不太关心垂直拆分。但是,我在 13"显示器上进行编码,这使得垂直空间相当宝贵。 我想要一些设置,当我执行 C-x 2 时,我的窗口不是拆分为 50/50,而是拆分为
我开始使用 CLisp,因此也开始使用 Emacs,包括“SLIME”插件(或其他名称。它是怎么称呼的?) 所以我使用 REPL 已经有一段时间了,并用 (defun) 在其中定义了很多函数。 不幸的
我正在使用 SLIME 学习 Common Lisp。有没有一种方法可以自动完成括号,这样当我输入一个开括号时,就会自动添加一个闭括号?我更喜欢 vim,所以在 mv ~/.vimrc 中我有: in
有没有人有在 Common Lisp 的控制台上使用 SLIME 的经验?我正在尝试学习 Practical Common Lisp,但书中的命令似乎不适用于 emacs/SLIME 的控制台版本。我
好的,我一定遗漏了一些明显的东西。从昨天开始我就被困住了,无法启动 Emacs-live + slime。 我正在使用 EMACS 24.3.1,安装了 Emacs-live,它运行良好(如果我在没有
我正在尝试使用 CVS (2009-01-05) 中的 Slime,但不断收到此错误: LOAD: A file with name /usr/share/common-lis
尽管我在任何地方都设置了 UTF-8(在我的 lein 项目、slime-lisp 组自定义、Emacs 缓冲区本身...),但在尝试运行诸如 (def beta "β") 之类的代码时,我一直收到此
我正在尝试通过《Common Lisp:符号计算的温和介绍》一书来学习 Common Lisp。此外,我正在使用 SBCL、Emacs 和 Slime。 在第 10 章结束时,作者讨论了有用的 bre
我正在尝试在 Emacs 中使用 SLIME。 在 SLIME REPL 中,输入 ,(逗号)会导致错误 Comma not inside a backquote. 输入 quit 而不是 The v
在 Emacs 中使用 Slime repl 进行开发时,我无法重新加载多方法。 重新定义 defmethod 表单可以正常工作,但如果我更改调度功能,我似乎无法重新加载 defmulti 表单。我想
我正在寻找一种更好的技术来做到这一点。我的普遍问题是调试器进入太晚或太早而无法捕获变量的值。 我首先尝试的是: (loop for i from 0 to 10 do (break)) 当调试器进
我正在尝试为 *.lisp 文件添加自动完成功能。我的粘液设置是: (add-to-list 'load-path "~/.emacs.d/plugins/slime/") (setq slime-l
所以我最近一直在努力学习Lisp。不幸的是,似乎没有任何效果 - 我正在关注 this Common Lisp tutorial但是当我第二次尝试运行 (hello-world) 时,它没有做同样的事
我已经安装了 Emacs + SBCL + slime,但我遇到了 slime 的问题。我在 Mac OS X 10.7.4 上 当我使用 M-x slime 时,我在顶部有两个屏幕 scratch,
我认为这曾经在 Emacs 23 中开箱即用,但在 24 中则不然。 那么,假设我已经加载了 Quicklisp 的 Alexandria 包。例如,如果我在 REPL 中运行 (apropos "c
我是一名优秀的程序员,十分优秀!