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.203541.23931@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> <13268@ptolemy-ri.arc.nasa.gov> Date: Sat, 1 Jun 91 20:35:41 GMT Lines: 30 In article <13268@ptolemy-ri.arc.nasa.gov> kthompso@ptolemy.arc.nasa.gov (Kevin Thompson) writes: >Well this sounds great, and would be. For what the original poster requested, it *is* great. > But is there an >implementation-independent way (or even implementation-dependent :) to >""? No, there's no portable way to print a structure the normal way, except by writing a structure-specific function that has the structure slot names hard-coded into it, e.g. (defun print-foo (object stream depth) (if (< depth *print-level*) (format stream "#S(~S :A ~S :B ~S)" 'foo (foo-a object) (foo-b object)) (write-char #\# stream))) There isn't necessarily even an implementation-dependent way; an implementation might define the above style of function as part of the DEFSTRUCT expansion. Since many implementations provide a way to discard structure slot information at run time, a generic structure printer may not be feasible. -- Barry Margolin, Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar