質問

I'm in a jiffy: just practicing manipulating lists and here is my code:

(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))))))

Yes I know that last function is long, but I've checked parentheses by hand and via minibuffer (check-parens)...and they seem to match. So...could someone please tell me why I'm getting SB:INPUT-ERROR-IN-COMPILE-FILE?

役に立ちましたか?

解決

To recap:

  1. There was a trailing parenthesis missing. You seem to have added it now.
  2. '(Cannot locate string: invalid index) chokes because of the colon :
  3. locate-string has no variable list. You probably meant string.

And why not format the last function like so:

(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))))))
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top