史莱姆声称输入错误;所有括号都匹配

时间:2013-12-30 19:14:56

标签: emacs input common-lisp sbcl slime

我很兴奋:只是练习操作列表,这是我的代码:

(defun new-strand (size type)
  (if (= 0 size)
      nil
      (case type
        ((nstrand) (cons 'x (new-strand (1- size) 'nstrand)))
        ((nlist) (cons '(x) (new-strand (1- size) 'nlist))))))

(defun locate-string (string index) 
  (if (null list)
      '(Cannot locate string: invalid index)
      (if (= index 0)
          'string
          (locate-string (cdr string) (1- index)))))

(defun new-substring (string)
  (if (> (length (car string)) 1)
      (cons (new-strand (1- (length (car string))) 'nstrand) (cdr string))
      (cons '(x) (new-substring (cdr string)))))

(defun construct-string (string index)
  (append (reverse (new-substring (cdr (locate-string
                                         (reverse string)
                                         (- (length string) index)))))
          (cons (new-strand (1+ (length (car (locate-string string index))))
                            'nstrand)
                (new-substring (cdr (locate-string string index))))))

是的我知道最后一个功能很长,但是我已经用手和迷你缓冲区(check-parens)检查括号......它们似乎匹配。那么......有人可以告诉我为什么我会收到SB:INPUT-ERROR-IN-COMPILE-FILE?

1 个答案:

答案 0 :(得分:2)

回顾一下:

  1. 缺少一个尾随括号。你似乎现在已经添加了它。
  2. 由于冒号'(Cannot locate string: invalid index)
  3. :窒息
  4. locate-string没有变量 list 。你可能意味着 string
  5. 为什么不格式化最后一个函数:

    (defun construct-string (string index)
      (append 
       (reverse (new-substring (cdr (locate-string (reverse string) (- (length string) index))))) 
       (cons 
        (new-strand (1+ (length (car (locate-string string index)))) 'nstrand) 
        (new-substring (cdr (locate-string string index))))))