将大量文本粘贴到 tmux 中运行的 clojure repl 中会导致错误和混合文本
我在将多个函数定义粘贴到 tmux 中运行的 clojure repl 时遇到问题。 (一般情况是粘贴大量代码)
当我手动将以下 clojure 定义(作为一个粘贴操作)粘贴到未在 tmux 中运行的 clojure repl 中时,它粘贴得很好。
但是,当从 tslime 粘贴或直接粘贴到运行 clojure repl 的 tmux 时,某些最终定义的文本会出现乱码,并且只有部分定义能够正确完成。 (在 make-exponentiation def 周围变得混乱)
还有其他人经历过这种情况或者对可能发生的事情有任何想法吗?
; Some expiriments and exercises for
; Lecture 3B of SICP
(ns deriv)
(defn variable?
[x]
(symbol? x))
(defn same-variable?
[v1 v2]
(and (variable? v1) (variable? v2) (= v1 v2)))
(defn sum?
[x]
(and (seq? x) (= (first x) '+)))
(defn make-sum
[a1 a2]
(cond
(= a1 0) a2
(= a2 0) a1
(and (number? a1) (number? a2)) (+ a1 a2)
:else (list '+ a1 a2)))
(defn make-product
[a1 a2]
(cond
(or (= a1 0) (= a2 0)) 0
(= a1 1) a2
(= a2 1) a1
(and (number? a1) (number? a2)) (* a1 a2)
:else (list '* a1 a2)))
(defn product?
[x]
(and (seq? x) (= (first x) '*)))
(defn addend
[[op addend & augend]]
addend)
(defn augend
[[op addend & augend]]
(if (next augend)
(conj augend '+)
(first augend)))
(defn multiplier
[[op multiplier & multiplicand]]
multiplier)
(defn multiplicand
[[op multiplier & multiplicand]]
(if (next multiplicand)
(conj multiplicand '*)
(first multiplicand)))
(defn exponentiation?
[x]
(and (seq? x) (= (first x) '**)))
(defn base
[[op base exponent]]
base)
(defn exponent
[[op base exponent]]
exponent)
(defn make-exponentiation
[base exponent]
(cond
(= exponent 0) 1
(= exponent 1) base
:else (list '** base exponent)))
(defn deriv
[exp var]
(cond
(number? exp) 0
(variable? exp) (if
(same-variable? exp var)
1
0)
(sum? exp) (make-sum
(deriv (addend exp) var)
(deriv (augend exp) var))
(product? exp) (make-sum
(make-product (multiplier exp)
(deriv (multiplicand exp) var))
(make-product (multiplicand exp)
(deriv (multiplier exp) var)))
(exponentiation? exp) (make-product
(deriv (base exp) var)
(make-product
(exponent exp)
(make-exponentiation
(base exp)
(- (exponent exp) 1))))
:else
(throw (Exception. (str "unknown expression type -- DERIV " exp)))))
I'm having trouble pasting multiple function definitions into the clojure repl running in tmux. (the general case is pasting over a large amount of code)
When I manually paste the following clojure definitions (as one paste operation) into the clojure repl not running in tmux it pastes over fine.
But when pasting from tslime or directly into tmux running the clojure repl, some of the final defs get their text garbled and only some of the definitions get completed properly. (gets screwy around the make-exponentiation def)
Anyone else experience this or have any ideas on what might be going on?
; Some expiriments and exercises for
; Lecture 3B of SICP
(ns deriv)
(defn variable?
[x]
(symbol? x))
(defn same-variable?
[v1 v2]
(and (variable? v1) (variable? v2) (= v1 v2)))
(defn sum?
[x]
(and (seq? x) (= (first x) '+)))
(defn make-sum
[a1 a2]
(cond
(= a1 0) a2
(= a2 0) a1
(and (number? a1) (number? a2)) (+ a1 a2)
:else (list '+ a1 a2)))
(defn make-product
[a1 a2]
(cond
(or (= a1 0) (= a2 0)) 0
(= a1 1) a2
(= a2 1) a1
(and (number? a1) (number? a2)) (* a1 a2)
:else (list '* a1 a2)))
(defn product?
[x]
(and (seq? x) (= (first x) '*)))
(defn addend
[[op addend & augend]]
addend)
(defn augend
[[op addend & augend]]
(if (next augend)
(conj augend '+)
(first augend)))
(defn multiplier
[[op multiplier & multiplicand]]
multiplier)
(defn multiplicand
[[op multiplier & multiplicand]]
(if (next multiplicand)
(conj multiplicand '*)
(first multiplicand)))
(defn exponentiation?
[x]
(and (seq? x) (= (first x) '**)))
(defn base
[[op base exponent]]
base)
(defn exponent
[[op base exponent]]
exponent)
(defn make-exponentiation
[base exponent]
(cond
(= exponent 0) 1
(= exponent 1) base
:else (list '** base exponent)))
(defn deriv
[exp var]
(cond
(number? exp) 0
(variable? exp) (if
(same-variable? exp var)
1
0)
(sum? exp) (make-sum
(deriv (addend exp) var)
(deriv (augend exp) var))
(product? exp) (make-sum
(make-product (multiplier exp)
(deriv (multiplicand exp) var))
(make-product (multiplicand exp)
(deriv (multiplier exp) var)))
(exponentiation? exp) (make-product
(deriv (base exp) var)
(make-product
(exponent exp)
(make-exponentiation
(base exp)
(- (exponent exp) 1))))
:else
(throw (Exception. (str "unknown expression type -- DERIV " exp)))))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我几乎每天都使用 tmux。我通常使用 emacs + swank/slime 并且没有问题。 JLine 似乎也避免了这个问题。我尝试了 rlwrap 并注意到类似的行为。这肯定是一个 rlwrap 问题。如果您想保留正在使用的 REPL,我建议您尝试一下 JLine。您只需下载 jar 并将其放入您的路径中或将其声明为 Leiningen 依赖项。然后,您可以像这样启动带有 JLine 支持的 REPL:
之后您就可以开始了。
I use tmux almost daily. I normally use emacs + swank/slime and don't have issues. JLine seems to avoid this issue as well. I tried rlwrap instead and noticed similar behavior. This most certainly seems to be an rlwrap issue. If you want to keep the same REPL you are using I suggest giving JLine a try. You just need to download the jar and put it in your path or declare it as a Leiningen dependency. You can then start a REPL up with JLine support like so:
After that you should be good to go.