Saturday, February 4, 2012

I want to make a match function in common lisp , how ?

i defined the following structs in lips ,





(defstruct book


name


writer


price


isbn)








(setf b1 (make-book :name "HarryPotter and the Deathly Hallows"


:writer "JK Rowling"


:price "RM45.00"


:isbn "01509741"))





(setf b2 (make-book :name "The Savage Detectives"


:writer "Roberto Bolano"


:price "RM45.00"


:isbn "02442817"))





(setf b3 (make-book :name "The Yiddish Policemens Union"


:writer "Michael Chabon"


:price "RM45.00"


:isbn "03952558"))





now i want to make a function to perform a search by name , how can i do it ???|||You've set b1 to a list of a single structure, b2 to the same, b3 to the same, etc. What you haven't done is to combine all the structures into a single list that can be searched. Execute something like this to create a single list (or CONS them together one at time):





(setf mydatabase b1 b2 b3)





Then you can work your way through mydatabase, checking to see if the book name matches each structure.

No comments:

Post a Comment