This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

simple list question

3 posts · 2063 views

hello all,

I'm new to lisp and was making a simple program.

4 lists with classes of 4 different students
1 list wit the names of the 4 lists
so to display all the classes from all the students i used a dolist function inside a do list function.
when i do this.. i get the error:
- ENDP: A proper list must not end with STUDENT1

i figure this is because lisp thinks that student1 is a string and not a list. is there a way that i can tell lisp that the string is the actually a list.

(setf student1 '((Math 320) (Itec 305) (Csci 355) (Csci 330) (Math 460) (Ieng 245))) ;List of my classes
(setf student2 '((Math 120) (Itec 205) (Csci 205) (Ieng 245))) ;List of first made up student
(setf student3 '((Math 350) (Csci 355) (Csci 330) (Math 460))) ;List of Second made up student
(setf student4 '((Math 320) (Csci 400) (Csci 200) (Math 120) (Ieng 332))) ;List of third made up student

(setf allStudents (student1 student2 student3 student4)) ;List of all 4 students


(defun showClass(cname) ;Show all courses of a subject
(dolist (studentName allStudents)

(dolist (subject studentName)
(print subject)
)

)

)



thanks for the future
Alex

Re: simple list question

Try changing
(setf allStudents '(student1 student2 student3 student4))
to
(setf allStudents (list student1 student2 student3 student4))
You want studentName to contain that student's list, not just their name.

P.S. The correct way to define global variables is either
(defvar allStudents (list student1 student2 student3 student4))
or
(defparameter allStudents (list student1 student2 student3 student4))
Where defparameter sets the variable each time it is called, but defvar only sets it if the variable didn't previously exist.

Re: simple list question

ok i got it, thank you