[plt-scheme] writing structures
Pedro Pinto wrote:
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>Hi there,
>
>I am trying to serialize a structure I created using:
>
>(define-struct my-struct (field1 field2 field3))
>(define s (make-my-struct 1 2 3))
>
>Ideally I would like to simply use:
>
>(write s port)
>
>and
>
>(define s (read port))
>
>Is something like this possible?
>
>Thanks in advance,
>-p
>
>
>
Look in the MzScheme manual, in the 'Built-in Parameters' section in the
'Threads' chapter. There are a few parameters for customising how things
are printed.
Or, if you used Swindle, you could do:
(defclass <my-class> (<object>)
(field1 :initarg :field1)
(field2 :initarg :field2)
(field3 :initarg :field3))
(defmethod print-object ((obj <my-class>) write? outport)
[insert how you print stuff here])
(define my-obj (make <my-class> :field1 'a :field2 'b :field3 'c))
(print-object my-obj #t (current-output-port))