From: Chris Wright
Subject: read / prin1 question
Date: 
Message-ID: <d2dc3928.0402252255.6c1ebab6@posting.google.com>
I want to write a hash-table to a file and then read it later. I'm
relying on
"prin1 produces output suitable for input to read." from the
HyperSpec.

But I get an error. I've tried Googling and the lisp FAQ. I'd be
grateful for help

cheers

Chris

Code sample:

<17:34>~ $: uname -a
Darwin Chris-Wrights-Computer.local 7.2.0 Darwin Kernel Version 7.2.0:
Thu Dec 11 16:20:23 PST 2003; root:xnu/xnu-517.3.7.obj~1/RELEASE_PPC 
Power Macintosh powerpc

 <17:37>~ $: sbcl 
This is SBCL 0.8.8, an implementation of ANSI Common Lisp.

More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
* (defvar *t* (make-hash-table))

*T*
* (with-open-file (str "test" :direction :output)
        (prin1 *t* str))

#<HASH-TABLE :TEST EQL :COUNT 0 {48016829}>
* (with-open-file (str "test" :direction :input)
        (read str))

debugger invoked on a READER-ERROR in thread 457:
  READER-ERROR at 2 (line 1, column 2) on #<FILE-STREAM
                                            for "file
\"/Users/caw/test\""
                                            {4807EFD9}>:
illegal sharp macro character: #\<

You can type HELP for debugger help, or (SB-EXT:QUIT) to exit from
SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [ABORT   ] Reduce debugger level (leaving debugger, returning to
toplevel).
  1: [TOPLEVEL] Restart at toplevel READ/EVAL/PRINT loop.
(SB-IMPL::%READER-ERROR
 3
 #<FILE-STREAM for "file \"/Users/caw/test\"" {4807EFD9}>
 "illegal sharp macro character: ~S")[:EXTERNAL]

From: Yang, Chul-Woong
Subject: Re: read / prin1 question
Date: 
Message-ID: <%Qg%b.133124$S3.1463422@news.bora.net>
Not all objects in lisp cannot be dumped for reuse with prin1.
Reader macro #<...> indicate that it cannot be read with 'read'.
You should do prin1 for each entry with maphash.

Regards,
Yang, Chul-Woong

Chris Wright wrote:

> I want to write a hash-table to a file and then read it later. I'm
> relying on
> "prin1 produces output suitable for input to read." from the
> HyperSpec.
> 
> But I get an error. I've tried Googling and the lisp FAQ. I'd be
> grateful for help
> 
> cheers
> 
> Chris
> 
> Code sample:
> 
> <17:34>~ $: uname -a
> Darwin Chris-Wrights-Computer.local 7.2.0 Darwin Kernel Version 7.2.0:
> Thu Dec 11 16:20:23 PST 2003; root:xnu/xnu-517.3.7.obj~1/RELEASE_PPC 
> Power Macintosh powerpc
> 
>  <17:37>~ $: sbcl 
> This is SBCL 0.8.8, an implementation of ANSI Common Lisp.
> 
> More information about SBCL is available at <http://www.sbcl.org/>.
> SBCL is free software, provided as is, with absolutely no warranty.
> It is mostly in the public domain; some portions are provided under
> BSD-style licenses.  See the CREDITS and COPYING files in the
> distribution for more information.
> * (defvar *t* (make-hash-table))
> 
> *T*
> * (with-open-file (str "test" :direction :output)
>         (prin1 *t* str))
> 
> #<HASH-TABLE :TEST EQL :COUNT 0 {48016829}>
> * (with-open-file (str "test" :direction :input)
>         (read str))
> 
> debugger invoked on a READER-ERROR in thread 457:
>   READER-ERROR at 2 (line 1, column 2) on #<FILE-STREAM
>                                             for "file
> \"/Users/caw/test\""
>                                             {4807EFD9}>:
> illegal sharp macro character: #\<
> 
> You can type HELP for debugger help, or (SB-EXT:QUIT) to exit from
> SBCL.
> 
> restarts (invokable by number or by possibly-abbreviated name):
>   0: [ABORT   ] Reduce debugger level (leaving debugger, returning to
> toplevel).
>   1: [TOPLEVEL] Restart at toplevel READ/EVAL/PRINT loop.
> (SB-IMPL::%READER-ERROR
>  3
>  #<FILE-STREAM for "file \"/Users/caw/test\"" {4807EFD9}>
>  "illegal sharp macro character: ~S")[:EXTERNAL]
From: Yang, Chul-Woong
Subject: Re: read / prin1 question
Date: 
Message-ID: <0Sg%b.133126$S3.1463366@news.bora.net>
Not all objects in lisp can be dumped for reuse with prin1.
Reader macro #<...> indicate that it cannot be read with 'read'.
You should do prin1 for each entry with maphash.

Regards,
Yang, Chul-Woong

Chris Wright wrote:

> I want to write a hash-table to a file and then read it later. I'm
> relying on
> "prin1 produces output suitable for input to read." from the
> HyperSpec.
> 
> But I get an error. I've tried Googling and the lisp FAQ. I'd be
> grateful for help
> 
> cheers
> 
> Chris
> 
> Code sample:
> 
> <17:34>~ $: uname -a
> Darwin Chris-Wrights-Computer.local 7.2.0 Darwin Kernel Version 7.2.0:
> Thu Dec 11 16:20:23 PST 2003; root:xnu/xnu-517.3.7.obj~1/RELEASE_PPC 
> Power Macintosh powerpc
> 
>  <17:37>~ $: sbcl 
> This is SBCL 0.8.8, an implementation of ANSI Common Lisp.
> 
> More information about SBCL is available at <http://www.sbcl.org/>.
> SBCL is free software, provided as is, with absolutely no warranty.
> It is mostly in the public domain; some portions are provided under
> BSD-style licenses.  See the CREDITS and COPYING files in the
> distribution for more information.
> * (defvar *t* (make-hash-table))
> 
> *T*
> * (with-open-file (str "test" :direction :output)
>         (prin1 *t* str))
> 
> #<HASH-TABLE :TEST EQL :COUNT 0 {48016829}>
> * (with-open-file (str "test" :direction :input)
>         (read str))
> 
> debugger invoked on a READER-ERROR in thread 457:
>   READER-ERROR at 2 (line 1, column 2) on #<FILE-STREAM
>                                             for "file
> \"/Users/caw/test\""
>                                             {4807EFD9}>:
> illegal sharp macro character: #\<
> 
> You can type HELP for debugger help, or (SB-EXT:QUIT) to exit from
> SBCL.
> 
> restarts (invokable by number or by possibly-abbreviated name):
>   0: [ABORT   ] Reduce debugger level (leaving debugger, returning to
> toplevel).
>   1: [TOPLEVEL] Restart at toplevel READ/EVAL/PRINT loop.
> (SB-IMPL::%READER-ERROR
>  3
>  #<FILE-STREAM for "file \"/Users/caw/test\"" {4807EFD9}>
>  "illegal sharp macro character: ~S")[:EXTERNAL]
From: Yang, Chul-Woong
Subject: Re: read / prin1 question
Date: 
Message-ID: <B4h%b.133129$S3.1463908@news.bora.net>
Not all objects in lisp can be dumped for reuse with prin1.
Read macro #<...> indicates that it cannot be read with 'read'.
You should do prin1 for each entry with maphash.

Regards,
Yang, Chul-Woong

Chris Wright wrote:

> I want to write a hash-table to a file and then read it later. I'm
> relying on
> "prin1 produces output suitable for input to read." from the
> HyperSpec.
> 
> But I get an error. I've tried Googling and the lisp FAQ. I'd be
> grateful for help
> 
> cheers
> 
> Chris
> 
> Code sample:
> 
> <17:34>~ $: uname -a
> Darwin Chris-Wrights-Computer.local 7.2.0 Darwin Kernel Version 7.2.0:
> Thu Dec 11 16:20:23 PST 2003; root:xnu/xnu-517.3.7.obj~1/RELEASE_PPC 
> Power Macintosh powerpc
> 
>  <17:37>~ $: sbcl 
> This is SBCL 0.8.8, an implementation of ANSI Common Lisp.
> 
> More information about SBCL is available at <http://www.sbcl.org/>.
> SBCL is free software, provided as is, with absolutely no warranty.
> It is mostly in the public domain; some portions are provided under
> BSD-style licenses.  See the CREDITS and COPYING files in the
> distribution for more information.
> * (defvar *t* (make-hash-table))
> 
> *T*
> * (with-open-file (str "test" :direction :output)
>         (prin1 *t* str))
> 
> #<HASH-TABLE :TEST EQL :COUNT 0 {48016829}>
> * (with-open-file (str "test" :direction :input)
>         (read str))
> 
> debugger invoked on a READER-ERROR in thread 457:
>   READER-ERROR at 2 (line 1, column 2) on #<FILE-STREAM
>                                             for "file
> \"/Users/caw/test\""
>                                             {4807EFD9}>:
> illegal sharp macro character: #\<
> 
> You can type HELP for debugger help, or (SB-EXT:QUIT) to exit from
> SBCL.
> 
> restarts (invokable by number or by possibly-abbreviated name):
>   0: [ABORT   ] Reduce debugger level (leaving debugger, returning to
> toplevel).
>   1: [TOPLEVEL] Restart at toplevel READ/EVAL/PRINT loop.
> (SB-IMPL::%READER-ERROR
>  3
>  #<FILE-STREAM for "file \"/Users/caw/test\"" {4807EFD9}>
>  "illegal sharp macro character: ~S")[:EXTERNAL]
From: Thomas A. Russ
Subject: Re: read / prin1 question
Date: 
Message-ID: <ymi8yipu1xc.fsf@sevak.isi.edu>
"Yang, Chul-Woong" <······@aratech.co.kr> writes:

> 
> Not all objects in lisp can be dumped for reuse with prin1.
> Read macro #<...> indicates that it cannot be read with 'read'.
> You should do prin1 for each entry with maphash.
> 
> Regards,
> Yang, Chul-Woong

And a good way to catch this at write (rather than read) time is to bind
the output control variable *print-readably* to T.  Conforming print
functions should then signal an error if they are unable to print a
particular form in a readable fashion.

> Chris Wright wrote:
> 
> > I want to write a hash-table to a file and then read it later. I'm
> > relying on
> > "prin1 produces output suitable for input to read." from the
> > HyperSpec.
> > 
> > But I get an error. I've tried Googling and the lisp FAQ. I'd be
> > grateful for help

You should also investigate MAKE-LOAD-FORM.

-- 
Thomas A. Russ,  USC/Information Sciences Institute