开发者

pasting a large amount of text into the clojure repl running in tmux results in errors and mixed up text

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 开发者_Python百科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 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:

java -cp "lib/*:lib/dev/*" jline.ConsoleRunner clojure.main

After that you should be good to go.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜