Subject: Re: constants in functions
From: Erik Naggum <clerik@naggum.no>
Date: 1998/03/21
Newsgroups: comp.lang.lisp
Message-ID: <3099464838956972@naggum.no>


* Sam Steingold
| (defun note-add (obj new)
|   (setf (slot-value 'note obj)
| 	(concatenate 'string (slot-value 'note obj) (string #\newline) new)))
| 
| I don't want each call to note-add to re-compute (string #\newline).

(defconstant newline-string (string #\newline))

  depending on how often I would print the notes and how often I would add
  notes, I think I would have used a (reversed) list of note lines that I
  would then print out with something like this:

(format <wherever> "~{~&~A~}" (reverse (slot-value 'note obj)))

  note that the printer could put this string back into place once it had
  computed it, and the first note to be printed could very well by a
  multi-line note:

(defun print-note (object &optional (stream *standard-output*))
  (let ((formatted-note
	 (format nil "~{~A~^~%~}" (nreverse (slot-value 'note object)))))
    (setf (slot-value 'note object) (list formatted-note))
    (write formatted-note :stream stream :escape nil)))

(defun note-add (object note)
  (push note (slot-value 'note object)))

#:Erik
-- 
  religious cult update in light of new scientific discoveries:
  "when we cannot go to the comet, the comet must come to us."