[racket] Question about reading string on a file

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Tue May 17 15:19:00 EDT 2011

>  I want to write an A-List on a file "Diary.txt" , this A-list contains
> couples of a symbol and a string. Example : '((17/05/2011 "Hello guys")
> (18/05/2011 "good morning")) .
> But I have a problem when I read this A-List from the file with the function
> (read p-in), it transforms strings to symbol .. like that : '((17/05/2011
> Hello guys) (18/05/2011 good morning))
> How to get back the A-List with strings like on my example ?

How are you writing the association list to disk?  Are you using
write?  The following example shows that _write_ and _read_ should
work for alists.

#lang racket

(require rackunit)     ;; unit testing framework

;; Let's write an alist to an in-memory port.
(define op (open-output-bytes))
(define alist '((greeting "bonjour!") (language "french")))
(write alist op)
(close-output-port op)

;; Now let's try reading it back in, and see that we get the
;; same content.
(define ip (open-input-bytes (get-output-bytes op)))
(define the-content (read ip))
(check-equal? the-content alist)

Posted on the users mailing list.