what is cd in (cd *db*)?

Discussion of Common Lisp
Post Reply
mohsen
Posts: 1
Joined: Fri Dec 03, 2010 4:34 pm

what is cd in (cd *db*)?

Post by mohsen » Sun Dec 05, 2010 7:35 pm

In Practical Common Lisp there's a code that helps display a list in a much cleaner form

Code: Select all

(defun dump-db ()
  (dolist (cd *db*)
    (format t "~{~a:~10t~a~%~}~%" cd)))
The syntax for dolist is described as
dolist (var list-form [result-form]) declaration* {tag | statement}*
but I i can't quite figure out what cd is in (cd *db*)

could someone help me crack this one?

That would be great!!

Thanks,
-m

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: what is cd in (cd *db*)?

Post by ramarren » Mon Dec 06, 2010 12:16 am

Code: Select all

(dolist (cd *db*)
dolist (var list-form [result-form])
In the syntax descriptions in CLHS top level parentheses are omitted and [] denotes optional component. This is modified Backus-Naur Form. Knowing this you should be able to figure out what "cd" corresponds to.

JamesF
Posts: 98
Joined: Thu Jul 10, 2008 7:14 pm

Re: what is cd in (cd *db*)?

Post by JamesF » Mon Dec 06, 2010 3:07 pm

Hint: that's not the only place you see that symbol. Look at how it's used elsewhere in the function, and it should start to make sense.
The documentation should also help.

Warren Wilkinson
Posts: 117
Joined: Tue Aug 10, 2010 11:24 pm
Location: Calgary, Alberta
Contact:

Re: what is cd in (cd *db*)?

Post by Warren Wilkinson » Mon Dec 06, 2010 9:08 pm

Code: Select all

(dolist (a '(1 2 3 4))
   --body--code--)
Could be rewritten as

Code: Select all

(destructuring-bind (a . rest) '(1 2 3 4)
   (tagbody :start 
      --body--code--
      (setf a (car rest) rest (cdr rest))
      (when rest (goto :start))))
If that helps.
Need an online wiki database? My Lisp startup http://www.formlis.com combines a wiki with forms and reports.

Vivitron
Posts: 4
Joined: Mon Nov 22, 2010 2:05 pm

Re: what is cd in (cd *db*)?

Post by Vivitron » Wed Dec 08, 2010 12:56 pm

dolist (var list-form [result-form]) declaration* {tag | statement}*
Cd is the var and *db* is the list-form, and the optional result-form is not used. There can be any number of declaration; there are none. There can be any number of tag or statement; there are no tags and the only statement is (format t ...).

I second Rmarren's suggestion to take a look at BNF.

Roughly: "For every album in the database, print it like this."

Historical note: when PCL was published CDs were a common physical medium for distributing albums :lol:

Post Reply