经过几次尝试和错误,我的添加电影功能似乎不起作用。它接受一个电影结构和一个数组。如果数组未满并且没有重复项,它将电影添加到数组中。
(defstruct movie
title director year type)
(defun add-movie (movie array)
(let ((mtitle (movie-title movie)))
(dotimes i (length array)
(if (not (equal (aref array i) NIL))
(let ((atitle (movie-title (aref array i))))
(if (equal atitle mtitle) (return nil)
(setf (aref array i) movie)))
(progn
(setf (aref array i) movie)
(return nil))))))
Trying it out results in error:
CL-USER> (defvar a (make-array 4 :initial-element NIL))
CL-USER> (add-movie (make-movie :title "Titanic" :director "James Cameron" :year 1997 :type "Romance") a)
当我在 CLISP 中输入你的函数
add-movie
时,我收到此错误:
*** - DOTIMES: I does not match lambda list element
(SYSTEM::VAR SYSTEM::COUNTFORM &OPTIONAL SYSTEM::RESULTFORM)
您希望语法正确。
在此处检查宏
dotimes
的语法:CLHS:宏 DOTIMES