[plt-scheme] how read list

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Thu May 17 13:44:53 EDT 2007

>  i have text
>  "{"Dialogs",
> {"Frame",

[text cut]
> how i can fast read it as list?
> How escape "," on reader?
> Replace to whitespace - not optimal, because text may be very long (more
> than 2M)

Just to mention: you could also just read in the structure, commas and 
all, and then flatten out all the superfluous structure afterwards.

Here's some code to show what I mean:

(module flatten-bananas mzscheme

   (require (lib "plt-match.ss"))

   (provide flatten-bananas)

   ;; Remove bananas from our datum.
   (define (flatten-bananas datum)
     (match datum
       ((list 'banana subdatum)
        (flatten-bananas subdatum))
       ((list elts ...)
        (map flatten-bananas elts))

For example:

> (flatten-bananas '((banana
((monana ana))

> (flatten-bananas '(ingredients (banana cream)
                                  (banana milk)
                                  (banana strawberry)))
(ingredients cream milk strawberry)

Hmm... getting hungry.  In any case, hope this helps!

Posted on the users mailing list.