Week 6 comments, questions
INPUT/OUTPUT
Course:  I      NTRODUCTION TO LISP
instructor:  jgw



Answers to questions assigned
============================================
Q 9.4
Write a recursive function NINETY-NINE-BOTTLES that sings the well-know
song "Ninety-nine Bottles of Beer on the Wall."

Answer:
(defun NINETY-NINE-BOTTLES (n)
 (cond ((zerop n)(format t "Honey!  Can you get me another beer.~%))
(t (format t "~&~S bottles of beer on the wall~%~S bottles of beer,~%
take one down, guzzle it down ~% ~S bottles of beer on the wall." n n (- n
1) (beers (- n 1)) ))))
==============================================
Q: 9.7
.. keeps reading data from the terminal until it reads ... COOKIE.  Write
COOKIE-MONSTER [function].
A"
(defun cookie-m ()
  (format t "Give me  cookie: ")
  (let ((x (read)))
  (if (equal x 'cookie)
       (format t "UM GOOD.  Cookie. ~%")
  (format t "No want ~S " x))))
=============================================
Q: 10.1
(Defun sell (n) "Ye Olde Lemonade Shop..... (pg 320)
(setf *total-glasses 0)
A:
    Suppose we forgot to set *total-glasses* to 0   what would happen?
Unbound error.
  Suppose we initialized *total-glasses* to 'foo?   Not a number.
=================================================
Q: 10.2
Rewrite the lemonade stand SELL function to use INCF instead of SETF.
A:
(defun sell (n) "Ye Olde Lemonade Stand: Sales by the Glass."
(setf *total-glasses* (incf *total-glasses* n))
(format t "~&That makes ~S glasses so far today."  *total-glasses*))
================================================
Q: 10.4
Write a function FORGET that removes a person from the *FRIENDS* list.
answer:
(setf *list-of-names* '(bill ted bob jane))
(defun FORGET ()
  (format t "~&Please enter a name: ")
  (let ((named(read)))
  (cond
       ((member named *list-of-names*)(remove named *list-of-names*))
               ((format t "~&~S is not at this address." named)))))
=================================================
[tough question]
Q: 10.5
Rewrite the following UGLY function to use good Lisp style.
Answer:
(defun unugly (x y)
  (when (> x y)
  (let* ((temp-y y)(x y)(x temp-y)))
  (setf avg (/ (+ x y) 2.0))
  (setf pct (* 100 (/ avg y)))
  (format t "~&average ~S is ~S percent of max" avg pct)))

============================================


               Q: 10.7
               What is wrong with the expressions (SETF (LENGTH X)3)?
               A:  LENGTH reads a condition.  It doesn't assign.
================================================
================================================
================================================




Misc questions suggested for discussion:

1)  Considering writing to files with WITH-OPEN-DATA ... How likely is it
to write an endless loop to a file if you don't set up the parenthesis
properly?

2)  How does WITH-OPEN-FFILE know how to write new lines to a file?  For
example:
(save-tree-data "The West Ridge" ((45 redwood) (22 oak) (43 maple)) 110)
writes 3 lines to a file even though I can enter it on one line in the
interpreter.

3)   The ability to read individual lines from a file is powerful.  Does
LISP require any delimiters to read lines from a file?


4)  Does PUSH and POP have any hardware capability?  Does LISP have any
built in functions to access the computer's memory, stack, registers,
address buses, etc., using push and pop?  Sort of like BASIC?





comments:
What's intriguing about end of file (EOF), is the example in 9.11 returned
the length of the file.