From: ·····@lirmm.fr
Subject: CL: Transform result of print-unreadable-object into string or a symbol?
Date: 
Message-ID: <x5wx45t3l4.fsf@ticco.lirmm.fr>
Hello,

printing a CLOS object results in something like that:

#<#SET #345>

This is the outcome of the function print-object (which calls print-unreadable-object).
Is it possible to make a string or a symbol out of such a representation?

Any hints would be greatly appreciated. Thank you in advance.

	Andreas

Andreas DIETZ
CCIPE                           email : ·····@ticco.ccipe.montp.inserm.fr
Rue de la Cardonille            Tel   : (33) 67 14 29 70
F-34094 Montpellier Cedex 5     Fax   : (33) 67 54 24 32
FRANCE
-- 
Andreas DIETZ
CCIPE                           email : ·····@ticco.ccipe.montp.inserm.fr
Rue de la Cardonille            Tel   : (33) 67 14 29 70
F-34094 Montpellier Cedex 5     Fax   : (33) 67 54 24 32
FRANCE

From: Thomas A. Russ
Subject: Re: CL: Transform result of print-unreadable-object into string or a symbol?
Date: 
Message-ID: <TAR.96Mar28143234@hobbes.ISI.EDU>
In article <··············@ticco.lirmm.fr> ·····@lirmm.fr writes:

 > printing a CLOS object results in something like that:
 > 
 > #<#SET #345>
 > 
 > This is the outcome of the function print-object (which calls
 >  print-unreadable-object).
 > Is it possible to make a string or a symbol out of such a representation?

It would be easy to create a string or a symbol, but the more
fundamental question is what benefit you would hope to get from doing
that.  Perhaps if you could tell us why you want to do this, we could
suggest direct ways of accomplishing your goal.

--
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu    
From: Shannon Spires
Subject: Re: CL: Transform result of print-unreadable-object into string or a symbol?
Date: 
Message-ID: <svspire-2903961401350001@dialup93.nmia.com>
In article <··············@ticco.lirmm.fr> ·····@lirmm.fr writes:

> printing a CLOS object results in something like that:
> 
> #<#SET #345>
> 
> This is the outcome of the function print-object (which calls
>  print-unreadable-object).
> Is it possible to make a string or a symbol out of such a representation?

Yes, but why not rewrite print-object to output a more readable
representation for the object in the first place?

Shannon Spires
·······@sandia.gov
From: Kenny Tilton
Subject: Re: CL: Transform result of print-unreadable-object into string or a symbol?
Date: 
Message-ID: <4jl3q7$s63@betty.bway.net>
>>>>
printing a CLOS object results in something like that:

#<#SET #345>

This is the outcome of the function print-object (which calls 
print-unreadable-object).
Is it possible to make a string or a symbol out of such a representation?

Any hints would be greatly appreciated. Thank you in advance.

<<<<<<

This expression...

(format nil "~s" your-object)

..returns the string you want. By specifying nil for the stream you suppress 
any Listener output.
From: Luca Pisati
Subject: Re: CL: Transform result of print-unreadable-object into string or a symbol?
Date: 
Message-ID: <316B1A16.41C6@nichimen.com>
Kenny Tilton wrote:
> 
> >>>>
> printing a CLOS object results in something like that:
> 
> #<#SET #345>
> 
> This is the outcome of the function print-object (which calls
> print-unreadable-object).
> Is it possible to make a string or a symbol out of such a representation?
> 
> Any hints would be greatly appreciated. Thank you in advance.
> 
> <<<<<<
> 
> This expression...
> 
> (format nil "~s" your-object)
> 
> ..returns the string you want. By specifying nil for the stream you suppress
> any Listener output.

I suggest you modify only inside of a print-unreadable-object, if you want a different
printout.

(defmethod print-object ((object my-class) stream)
   (print-unreadable-object (object stream)
     (format stream "~A" (class-name my-class) ;; or whatever you want
     ))

Any other use of PRINT-OBJECT can be very dangerous, because it may undermine
the print/read mechanism.

PRINT-OBJECT responds also to many print variables, like *print-readably* and
*print-escape* (actually ANSI specifies the exact behaviour print-object should
have).

If you want to have alternate printing, I suggest you to drive it
with a cond inside of the print-object method.

Example:

(defmethod print-object ((object my-class) stream)
  (cond
     (*print-readably*
       (pprint (make-load-form object) stream))
     (*my-print-variable*
       (format stream "~S" (my-object-name object)))
     (t
       (print-unreadable-object (object stream)
         (format stream "~A" (class-name my-class))))
     ))


-- 
Luca Pisati              Nichimen Graphics Inc.
12555 West Jefferson Blvd. Suite 285, Los Angeles, CA 90066
Phone: (310) 577-0500; Fax: (310) 577-0577  ······@nichimen.com (internet)
From: Kenny Tilton
Subject: Re: CL: Transform result of print-unreadable-object into string or a symbol?
Date: 
Message-ID: <4jl3qe$2oc@betty.bway.net>
>>>>
printing a CLOS object results in something like that:

#<#SET #345>

This is the outcome of the function print-object (which calls 
print-unreadable-object).
Is it possible to make a string or a symbol out of such a representation?

Any hints would be greatly appreciated. Thank you in advance.

<<<<<<

This expression...

(format nil "~s" your-object)

..returns the string you want. By specifying nil for the stream you suppress 
any Listener output.
From: Chris Brew
Subject: Re: CL: Transform result of print-unreadable-object into string or a  symbol?
Date: 
Message-ID: <f3tyboggt2q.fsf@blair.cogsci.ed.ac.uk>
>>>>> In article <··············@ticco.lirmm.fr>, ·····@lirmm.fr writes:
In article <··············@ticco.lirmm.fr> ·····@lirmm.fr writes:


> Hello, printing a CLOS object results in something like that:

> #<#SET #345>

> This is the outcome of the function print-object (which calls
> print-unreadable-object).  Is it possible to make a string or a
> symbol out of such a representation?

(format nil <clos-object>) would produce "#<#SET #345>", which is
a string. If what you really want is to get a _meaningful_
string or symbol, then you have to tinker with methods
for print-object. There are also some PD routines
for saving and restoring objects in Mark Kantrowitz's
collection of utilities at CMU

Chris

-- 
------------------------------------------------------------------
Email: ··········@edinburgh.ac.uk
Address:  Language Technology Group, 
          HCRC, 2 Buccleuch Place,  Edinburgh EH8 9LW 
          Scotland
Telephone: +44 131 650 4631 
Fax:       +44 131 650 4587
------------------------------------------------------------------