[racket] Parsing a string into a quoted expr

From: Ryan Culpepper (ryan at cs.utah.edu)
Date: Mon Sep 12 19:19:56 EDT 2011

Use read and open-input-string:

 > (read (open-input-string "(+ 1 2)"))
'(+ 1 2)

You can use eval to evaluate that datum, but first read this section of 
the guide carefully: http://docs.racket-lang.org/guide/reflection.html

Ryan


On 09/12/2011 05:20 PM, Jeremy Kun wrote:
> I want to take a string which contains an expression and parse it as a
> quoted expression, which I can then potentially evaluate or manipulate.
>
> I noticed that the load function has this capability built into it, and
> I know at some point racket has to take strings and parse them into
> expressions. Is there a single function I can call to do this? If not,
> would it be trivial to write a reader extension to do this? As in, just
> read all characters in and quote the result.
>
> Or I might just be better off writing a function that matches
> parens...but it seems like reinventing the wheel when I don't have to.
>
> Thanks for the advice!
>
> Jeremy
>
>
>
> _________________________________________________
>    For list-related administrative tasks:
>    http://lists.racket-lang.org/listinfo/users


Posted on the users mailing list.