我无法将多个函数定义粘贴到在tmux中运行的clojure repl中。 (一般情况是粘贴大量代码)
当我手动将以下clojure定义(作为一个粘贴操作)粘贴到未在tmux中运行的clojure repl时,它会粘贴得很好。
但是当从tslime粘贴或直接进入运行clojure repl的tmux时,一些最终的def会使文本乱码,只有一些定义能够正确完成。 (在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)))))
答案 0 :(得分:1)
我几乎每天都使用tmux。我通常使用emacs + swank / slime并且没有问题。 JLine似乎也避免了这个问题。我尝试了rlwrap而注意到了类似的行为。这当然似乎是一个问题。如果你想保持你正在使用的相同REPL我建议尝试JLine。您只需要下载jar并将其放在路径中或将其声明为Leiningen依赖项。然后,您可以使用JLine支持启动REPL,如下所示:
java -cp "lib/*:lib/dev/*" jline.ConsoleRunner clojure.main
之后你应该好好去。