simple list question

Discussion of Common Lisp

simple list question

Postby alex3oo2 » Fri Oct 23, 2009 6:01 pm

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
alex3oo2
 
Posts: 2
Joined: Fri Oct 23, 2009 5:52 pm

Re: simple list question

Postby nuntius » Sat Oct 24, 2009 11:25 am

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.
User avatar
nuntius
 
Posts: 498
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

Re: simple list question

Postby alex3oo2 » Sat Oct 24, 2009 1:48 pm

ok i got it, thank you
alex3oo2
 
Posts: 2
Joined: Fri Oct 23, 2009 5:52 pm


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 5 guests