【发布时间】:2013-12-30 19:14:56
【问题描述】:
我很忙:只是练习操作列表,这是我的代码:
(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))))))
是的,我知道最后一个函数很长,但我已经手动和通过 minibuffer (check-parens) 检查了括号......它们似乎匹配。那么...有人可以告诉我为什么我会收到 SB:INPUT-ERROR-IN-COMPILE-FILE 吗?
【问题讨论】:
-
在最后加一个括号。
-
另外,CCL 不喜欢你的
'(Cannot locate string: invalid index)。尝试将其替换为字符串“无法定位字符串:无效索引”。 -
另外,locate-string 没有名为 list 的变量。
-
@x86ris:您可能想要安装 paredit 或 smartparens。一旦你使用了这样一个次要的模式,你真的必须不遗余力地得到不平衡的括号。除此之外,像 rainbow-delimiters-mode 这样的次要模式也可能会有所帮助:因为很明显,最后一个括号的颜色与 之前的括号不匹配defun ^ ^
标签: emacs input common-lisp sbcl slime