我很兴奋:只是练习操作列表,这是我的代码:
(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?
答案 0 :(得分:2)
回顾一下:
'(Cannot locate string: invalid index)
,:
窒息
locate-string
没有变量 list 。你可能意味着 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))))))