Reputation: 61
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?
Upvotes: 1
Views: 67
Reputation: 18937
To recap:
'(Cannot locate string: invalid index)
chokes because of the colon :
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))))))
Upvotes: 2