[plt-scheme] how read list

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed May 16 16:18:12 EDT 2007

At Wed, 16 May 2007 21:25:34 +0400, wwall wrote:
>   "{"Dialogs",
> {"Frame",
> [...]
> {"Cnt_Ver","10001"}}  "
> how i can fast read it as list?
> How escape "," on reader?

You can install a readtable that treats comma as whitespace, and
otherwise behave like the existing readtable:

 >  (parameterize ([current-readtable
                    (make-readtable (current-readtable)
                                    #\, #\space #f)])
 {1, 2, 3} ; <- the input
 (1 2 3)   ; <- printed form of the result

Some possibly-relevant information is lost this way, though. I see that
your data includes pieces like


By treating comma as whitespace, you lose the information that the last
five strings were not separated by commas.

So, depending on your needs, you may want to treat comma like a symbol,

 >  (parameterize ([current-readtable
                    (make-readtable (current-readtable)
                                    #\, #\x #f)])
 {"a", "b" "c"} ; <- the input
 ("a" |,| "b" "c") ; <- printed form of the result

and then you can process this list to remove the commas and concatenate
adjacent strings.

Yet another possibility is to change the readtable so that the parser
for #\" detects when the closing doublequote is followed by an
immediate doublequote. That's more work, because you have to write a
character-level parsing procedure and install it like this (assuming
that it's named `parse-string-sequence'):

 (parameterize ([current-readtable
                  #\, #\space #f
                  #\" 'terminating-macro parse-string-sequence)])


Posted on the users mailing list.