Skip to content

Commit

Permalink
mooooooore
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingmachine committed Feb 18, 2012
1 parent 3435895 commit cccc252
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -2,4 +2,5 @@
city*
known-city*
*.fas
*.lib
*.lib
*.tmp
38 changes: 38 additions & 0 deletions practical-common-lisp/cddb.lisp
Expand Up @@ -7,3 +7,41 @@
(defun dump-db ()
(dolist (cd *db*)
(format t "~{~a:~10t~a~%~}~%" cd)))

(defun prompt-read (prompt)
(format *query-io* "~a: " prompt)
(force-output *query-io*)
(read-line *query-io*))

(defun prompt-for-cd ()
(make-cd
(prompt-read "Title")
(prompt-read "Artist")
(or (parse-integer (prompt-read "Rating") :junk-allowed t) 0)
(y-or-n-p "Ripped [y/n]")))

(defun add-cds ()
(loop (add-record (prompt-for-cd))
(if (not (y-or-n-p "Another? [y/n]: ")) (return))))

(defun save-db (filename)
(with-open-file (out filename
:direction :output
:if-exists :supersede)
(with-standard-io-syntax (print *db* out))))

(defun load-db (filename)
(with-open-file (in filename)
(with-standard-io-syntax
(setf *db* (read in)))))

(defun select (selector-fn)
(remove-if-not selector-fn *db*))

(defun where (&key title artist rating (ripped nil ripped-p))
#'(lambda (cd)
(and
(if title (equal (getf cd :title) title) t)
(if artist (equal (getf cd :artist) artist) t)
(if rating (equal (getf cd :rating) rating) t)
(if ripped-p (equal (getf cd :ripped) ripped) t))))
18 changes: 18 additions & 0 deletions practical-common-lisp/notes.textile
Expand Up @@ -28,6 +28,24 @@ h2. Ch 3 A Simple Database
** ~{ : the next argument must be a list. Loops over list, processing
the directives between the braces.
** ~% : emit newline
* Y-OR-N-P - requires input of Y y N or n
* WITH-OPEN-FILE opens file, binds the stream to a variable, executes
a set of expressions, and then closes the file.
* PRINT outputs in lisp format
* WITH-STANDARD-IO-SYNTAX ensures that certain variables that affect
the behavior of PRINT are set to their standard values
* REMOVE-IF-NOT like ruby's reject
* Keyword parameters
Example: (defun foo (&key a (b 20) (c 30 c-p)) (list a b c c-p))
when called:
(foo :a 1 :b 2 :c 3) -> (1 2 3 T)
(foo :a 1 :c 3) -> (1 20 3 T)
(foo) -> (NIL 20 30 NIL)

When giving a list to a keyword argument, the first item is the
name, second default value, third t/f on whether argument was
actually passed

h2. Slime

* C-c C-c : compile function
Expand Down

0 comments on commit cccc252

Please sign in to comment.