Startpunkten
This commit is contained in:
102
Lisp_Database/db.lisp
Normal file
102
Lisp_Database/db.lisp
Normal file
@@ -0,0 +1,102 @@
|
||||
; ==========================================
|
||||
; # Laboration 2 i Programspråk #
|
||||
; # LISP #
|
||||
; # ======================================== #
|
||||
; # Christian Ohlsson #
|
||||
; # Karlstads universitet #
|
||||
; # 1999-05-19 #
|
||||
; # =========================================
|
||||
|
||||
;Main function which starts the program
|
||||
;Prints welcome-msg and ask for yor choice
|
||||
(defun run ()
|
||||
(format t "~% Welcome to the database ")
|
||||
(format t "~% ======================= ")
|
||||
(format t "~% Press s to search, ")
|
||||
(format t "~% or 'x' to exit. ")
|
||||
(format t "~% ======================= ")
|
||||
(format t "~% ")
|
||||
(setq val (read))
|
||||
(cond ((equal val 's) (dosearch (getdb)) (run))
|
||||
((equal val 'x) (format t "~%Exiting") )
|
||||
(t (format t "~% That's not a valid option") (run))
|
||||
)
|
||||
)
|
||||
;Prints out each found book on the screen
|
||||
(defun printbook(book)
|
||||
(when book
|
||||
(format t "~% Subject : ~a" (first book))
|
||||
(format t "~% Title : ~a" (second book))
|
||||
(format t "~% Publisher : ~a" (third book))
|
||||
(format t "~% Year : ~a" (fourth book))
|
||||
(printauthors (fifth book))
|
||||
(format t "~% ")
|
||||
(format t "~% ------------------------------------------------")
|
||||
)
|
||||
)
|
||||
|
||||
;Asks for the search value and then calls
|
||||
;the search-procedure
|
||||
(defun dosearch (library)
|
||||
(format t "~% Enter search: ")
|
||||
(setq value (read-line t))
|
||||
(getit library value)
|
||||
)
|
||||
|
||||
;Prints out the authors of each book
|
||||
(defun printauthors(authors)
|
||||
(when authors
|
||||
(format t "~% Author : ~a"(first authors))
|
||||
(printauthors (rest authors))
|
||||
)
|
||||
)
|
||||
|
||||
;Gets the subject, title, publisher, year and author
|
||||
;for each book found
|
||||
(defun getbook(book value)
|
||||
(cond
|
||||
((integerp(search value (first book))) (printbook book))
|
||||
((integerp(search value (second book))) (printbook book))
|
||||
((integerp(search value (third book))) (printbook book))
|
||||
((integerp(search value (fourth book))) (printbook book))
|
||||
((getauthor (fifth book) value) (printbook book))
|
||||
)
|
||||
)
|
||||
|
||||
;Searches recursivly throuh the library and
|
||||
;lets getbook see if it's a match,
|
||||
;and the do the same with the next book.
|
||||
(defun getit(library value)
|
||||
(when library
|
||||
(getbook (first library) value)
|
||||
(getit(rest library) value)
|
||||
)
|
||||
)
|
||||
|
||||
;Checks if it is a author
|
||||
(defun getauthor (authors value)
|
||||
(when authors
|
||||
(cond
|
||||
((integerp(search value (first authors))) t)
|
||||
(t (getauthor (rest authors) value))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
;Defines our database.
|
||||
(defun getdb ()
|
||||
(setf library '
|
||||
(
|
||||
( "C Lang" "From C to C An Intro to ANSI Standard C" "Harcourt Brace Jovanovic" "1989" ("Gardner J.") )
|
||||
( "Compilers" "Compilers Principles Techniques and Tools" "Addison Wesley" "1986" ( "Ullman J.D." "Aho A.V." "Sethi R.") )
|
||||
( "Compilers" "Compiler Design in C" "Prentice Hall" "1990" ( "Holub A.I.") )
|
||||
( "Databases" "An Introduction to Database Systems" "Addison Wesley" "1995" ( "Date C.J.") )
|
||||
( "Databases" "The Theory of Relational Databases" "Computer Science Press" "1983" ( "Maier D.") )
|
||||
( "HCI" "Human-Computer Interaction" "Prentice Hall" "1993" ( "Dix A." "Finlay J." "Abowd G." "Beale R.") )
|
||||
( "Prog Langs" "Programming Languages Concepts & Constructs" "Addison Wesley" "1996" ( "Sethi R.") )
|
||||
( "Prog Langs" "Concepts of Programming Languages" "Addison Wesley" "1996" ( "Sebesta R.W.") )
|
||||
( "C Lang" "The C Programming Language" "Prentice Hall" "1988" ( "Kernighan B.W." "Ritchie D.M.") )
|
||||
( "Prog Langs" "Programming Languages Principles and Practice" "PWS Publishing" "1993" ( "Louden K.C." ))
|
||||
)
|
||||
)
|
||||
)
|
||||
14
Lisp_Database/read_me
Normal file
14
Lisp_Database/read_me
Normal file
@@ -0,0 +1,14 @@
|
||||
Readme fil för Lisp Lab i Programspråk
|
||||
---------------------------------------------
|
||||
|
||||
Sökbar databas med böcker.
|
||||
|
||||
Denna lab är provkörd och klar.
|
||||
Starta Lisp med: gcl
|
||||
skriv:
|
||||
(load "db.lisp")
|
||||
(run)
|
||||
för att köra programmet.
|
||||
|
||||
---------------------------------------------
|
||||
Christian Ohlsson. di7chro@cse.kau.se
|
||||
Reference in New Issue
Block a user