[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

a problem with print-functions



    Date: Fri, 27 May 88 14:37 EDT
    From:     Stever@IVORY.S4CC.Symbolics.COM (Stephen Robbins)

	Date: Fri, 27 May 88 11:25:33 EDT
	From:     bds@mitre-bedford.ARPA

    (defstruct (foo (:print-function print-random-object))
      ...)

    (defun print-random-object (object stream depth)
      (declare (ignore depth))
      (format stream "#<~S structure ~S>"
	    (type-of object)
	    #+3600 (sys:%pointer object)
	    #-3600 'address-unavailable))

Here's a useful idea if you do ever intend to port your code.  Sometimes
it's hard to tell structures apart, even if they have names, since you
might keep "dead" ones around for debugging purposes.  So I include the
following structure in my portable code.  Then I can use %pointer in all
my print-functions.

;;; -*- Mode: LISP; Syntax: Common-lisp; Package: (fake-pointer :use lisp) -*-

;;;; Distinguished structures

;;; By: Gumby@ai.ai.mit.edu (David Vinayak Wallace)
;;; Date: January 10, 1985

;;; Include the structure FAKE-POINTER in your structure defintions, and
;;; then you will be able to tell their printed representations apart.
;;; Use the %pointer function in your print-functions.

(in-package 'fake-pointer)
(provide "Fake-Pointer")
#+lispm (import 'sys:%pointer)
(export '(%pointer fake-%pointer))
(pushnew :fake-%pointer *features*)

#+nil(defmacro %pointer (thing)
       `(si:address-of ,thing))

(defvar *fake-pointer-counter* 0
  "Serial number of fake-%pointer structures created")

;;; This loses if you copy the includer, but I don't use that "feature" anyway:
(defstruct (fake-%pointer (:conc-name nil) (:constructor nil) (:copier nil))
  #-(or lispm nil)
  (%pointer (incf *fake-pointer-counter*) :read-only t))