Page 1 of 1

simple list question

Posted: Fri Oct 23, 2009 6:01 pm
by alex3oo2
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

Posted: Sat Oct 24, 2009 11:25 am
by nuntius
Try changing

Code: Select all

(setf allStudents '(student1 student2 student3 student4))
to

Code: Select all

(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

Code: Select all

(defvar allStudents (list student1 student2 student3 student4))
or

Code: Select all

(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

Posted: Sat Oct 24, 2009 1:48 pm
by alex3oo2
ok i got it, thank you