Input Lisp中的读取函数没有提示

Input Lisp中的读取函数没有提示,input,lisp,common-lisp,lispworks,Input,Lisp,Common Lisp,Lispworks,因此,我最近自学了lisp,并一直在胡闹一些程序。我正试图编写一个小程序,比较用户输入的类列表,找出哪些类可以一起工作。下面是第一部分,它从用户那里收集数据,并创建一些类创建时的列表 (defun class-entries () (setf Monday 0) ;initializes the days of the week

因此,我最近自学了lisp,并一直在胡闹一些程序。我正试图编写一个小程序,比较用户输入的类列表,找出哪些类可以一起工作。下面是第一部分,它从用户那里收集数据,并创建一些类创建时的列表

(defun class-entries ()

(setf Monday 0)                                                                                     ;initializes the days of the week 
(setf Tuesday 0)
(setf Wednesday 0)
(setf Thursday 0)
(setf Friday 0)

 (setf times 100)
 (dotimes (repeating times "You have reached the limit of entries")                                  ;repeats the following for the number of classes that you are comparing
  (dolist (dayofweek '(Monday Tuesday Wednesday Thursday Friday))                                    ;repeats the following for each day of the week
   (print (concatenate 'string "Does this class occur on " dayofweek " ?"))  
    (setf isday (read))
   (if (= isday 1)                                                                                   ;prompts the questions if there is a class that day
    (progn
     (print (concatenate 'string "What time does the class begin on " dayofweek " ?"))
     (setf starttime (read))
     (print (concatenate 'string "What time does the class end on " dayofweek " ?"))
     (setf endtime (read)))
     (setf isday 0))
   (if (= isday 0)                                                                                    ;Adds the list of (startime endtime) to the current day of week or nil if there isn't a class that day
    (setf 'dayofweek '"nil")
    (setf 'dayofweek '(starttime endtime))))
 (print "What is the title of the class?")
 (setf (read) '((mon (Monday)) (tues (Tuesday)) (wed (Wednesday)) (thurs (Thursday)) (fri (friday)))) ;sets a new variable to the values of the classes's hours
  (print "Is there another class?")                                                                   ;repeats the function for another class or ends it
   (setf isclass (read))
   (if (= isclass 0)
    (setf times 0)
    ()))
 (setf times 100)
)

当我对函数求值时,它只返回0,其他什么都不显示。我不确定这是因为我没有使用Listener还是什么。谢谢

我认为这个问题还不够详细,但这可能会对您有所帮助,并有望成为分解和提示的有用示例。添加一些附加检查并不太难:

(defun prompt (&optional (control "> ") &rest arguments)
  "Read a value from STREAM after presenting PROMPT."
  (fresh-line *terminal-io*)
  (apply 'format *terminal-io* control arguments)
  (finish-output *terminal-io*)
  (read *terminal-io*))

(defstruct course
  (name nil :type symbol :read-only t)
  (day nil :type symbol :read-only t)
  (start nil :type number :read-only t)
  (end nil :type number :read-only t))

(defun prompt-for-course ()
  (flet ((except-quit (x)
           (if (string-equal (princ-to-string x) "quit")
               (return-from prompt-for-course nil)
               x)))
    (let (name day start end)
      (setq name  (except-quit (prompt "course name: "))
            day   (except-quit (prompt "course day:  "))
            start (except-quit (prompt "start time:  "))
            end   (except-quit (prompt "end time:    ")))
      (make-course :name name
                   :day day
                   :start start
                   :end end))))

(defun prompt-for-courses ()
  (loop
     with courses = (make-hash-table)
     for course = (prompt-for-course)
     while course
     do (push course (gethash (course-day course) courses))
     finally (return courses)))

setf读取。。。没有道理。阅读不是一个你可以分配到的地方。这真的是没有错误的编译吗?你也不应该在函数中使用全局变量。应该使用let绑定局部变量,而不是使用setf来分配全局变量。分配变量时,不应引用该变量。setf“dayofweek”starttime endtime应为setf dayofweek列表starttime endtimesetf read旨在分配一个用户立即提供名称的变量。是的,没有错误。但可能有问题,因为用户输入不起作用。我将尝试更多地使用局部变量,谢谢。我引用了那个变量,因为我认为这会使它插入那个变量的值作为名称。由于该行位于函数dolist中,dayofweek的值应该是其中一天,希望处理的日期的值设置为“starttime endtime”。对于setf isday read之类的内容,请注意Common Lisp已经提供了返回布尔值的选项。
CL-USER> (prompt-for-courses)
course name: intro-logic
course day:  monday
start time:  1100
end time:    1250

course name: intermediate-logic
course day:  tuesday
start time:  1100
end time:    1250

course name: quit

#<HASH-TABLE :TEST EQL :COUNT 2 {1003EA6513}>