poor version of phonebook added by sepuku on Mon May 7 15:57:29 2012

;;;; This is the phonebook v.1 package. Every contact has 4 values:
;;;; 1)name 2)surname 3)phone 4)email
;;;;
;;;; TO DO: 
;;;; 1) replace contact-printer with a proc that does not use do
;;;; 2) write a proc that prints info by choice e.g. (email-of-user username)
;;;; or all info about a user



;; set phonebook location

(define phonebook (open-input-file "/home/sepuku/sicp/phonebook/phb.db"))

;;save phonebook

(define save-phonebook
  (lambda (path phonebook)
    (call-with-output-file path
      (lambda (output-port)
        (write phonebook output-port))
      #:append)))



;; make new contact

(define add-contact
  (lambda (n sur phn eml)
    (let ((pbook (cons phonebook
                       (list (cons 'name n)
                             (cons 'surname sur)
                             (cons 'phone phn)
                             (cons 'email eml)))))
      (save-phonebook "/home/sepuku/sicp/phonebook/phb.db" pbook))))

;; print all contacts on phonebook

(define contact-printer
  (lambda (file)
    (do ((line (read-line file) (read-line file))) ((eof-object? line))
        (display line)
        (newline))))