allegroserve :princ idea extended to :format
Andrew Philpot <[email protected]> Thu, 9 May 2002 11:25:00 -0700
| Newsgroups | gmane.lisp.open-source.franz |
|---|---|
| Message-ID | <[email protected]> |
I think using :format similarly to :princ et al makes sense. Features
like ~(, ~{, seem very handy.
I submit the following code.
;; This software is Copyright (c) University of Southern California,
;; 2002-05-09.
;; University of Southern California grants you the rights to distribute
;; and use this software as governed by the terms
;; of the Lisp Lesser GNU Public License
;; (http://opensource.franz.com/preamble.html),
;; known as the LLGPL.
(in-package :net.html.generator)
(defun format-http (fmt &rest vals)
;; formatted output the given value to the http stream
(apply #'format *html-stream* fmt vals))
(def-special-html :format
#'(lambda (ent args argsp body)
(declare (ignore ent args argsp))
`(progn (format-http ,@body)))
#'(lambda (ent cmd args form stream)
(declare (ignore ent args))
(assert (>= (length form) 2))
(if* (eq cmd :full)
then (progn
(apply #'format stream (cdr form)))
else (error ":format must be given format specifier")))
)
(defun format-safe-http (fmt &rest vals)
;; escaped formatted output the given value to the http stream
(emit-safe *html-stream* (apply #'format nil fmt vals)))
(def-special-html :format-safe
#'(lambda (ent args argsp body)
(declare (ignore ent args argsp))
`(progn (format-safe-http ,@body)))
#'(lambda (ent cmd args form stream)
(declare (ignore args ent))
(assert (>= (length form) 2))
(if* (eq cmd :full)
then (emit-safe stream
(apply #'format nil (cdr form)))
else (error ":format-safe must be given format specifier"))))