Newsgroups: comp.lang.lisp
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!barmar
From: barmar@think.com (Barry Margolin)
Subject: Re: shadowing defstruct print-function
Message-ID: <1991Jun1.202137.23293@Think.COM>
Sender: news@Think.COM
Reply-To: barmar@think.com
Organization: Thinking Machines Corporation, Cambridge MA, USA
References: <1991May31.183953.29579@jpl-devvax.jpl.nasa.gov>
Date: Sat, 1 Jun 91 20:21:37 GMT
Lines: 27

In article <1991May31.183953.29579@jpl-devvax.jpl.nasa.gov> charest@AI-Cyclops.JPL.NASA.GOV writes:
>Is it possible to shadow the print-function used to print a structure
>during a call to FORMAT?

Eric's suggestion with the *PRINT-FOO-HOOK* variable isn't bad.  Here's
what I thought of:

(flet ((temp-print-foo ...))
  (let ((real-print-foo (symbol-function 'print-foo)))
    (unwind-protect
        (progn
          (setf (symbol-function 'print-foo) #'temp-print-foo)
	  ...)
      (setf (symbol-function 'print-foo) real-print-foo))))

Symbolics has a LETF macro that makes this kind of thing much easier to
write.  It's like LET, except the variable bindings can be SETF places.  In
that case, one could write:

(letf (((symbol-function 'print-foo)
	#'(lambda ...)))
  ...)
-- 
Barry Margolin, Thinking Machines Corp.

barmar@think.com
{uunet,harvard}!think!barmar
