[plt-scheme] Reading and writing paths

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Fri Jan 5 21:13:10 EST 2007

> (I looked for a mentioning of paths in
> section 11.2.4 of the MzScheme manual, but
> didn't find anything)

Hi Jens,

According to section 11.2.5 in the mzscheme reference manual, paths are 
handled with this clause:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Paths (see section 11.3.1) by write like other unreadable values using 
#<path:...>. A path displays in the same way as the result of path->string 
applied to the path.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

So it's unREADable.  However, it does look like the serialize library will 
handle paths:

http://download.plt-scheme.org/doc/360/html/mzlib/mzlib-Z-H-39.html#node_chap_39

so that the following will work:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(module foo mzscheme
   (require (lib "serialize.ss"))

   (let ([out (open-output-string)])
     (write (serialize (string->path "c:/foo/bar.txt")) out)
     (printf "~s~n" (get-output-string out))
     (let ([in (open-input-string (get-output-string out))])
       (deserialize (read in)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


Best of wishes!


Posted on the users mailing list.