Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Parsing a string into s-expressions

3 views
Skip to first unread message

AndrewW

unread,
Nov 12, 2009, 7:05:17 AM11/12/09
to
In a program that I'm writing, I would like the option to read in a
file of additional scheme code and execute it at runtime with eval.

The program is built using Gambit and compiled up into an exe but I'd
like to pass a command line parameter of the filename of more scheme
code to execute at runtime.

Having coded this to read the file contents into a string and then
pass to eval, I realise my mistake which is eval merely executes the
string e.g. (eval "(+ 5 5)") i.e. it returns "(+ 5 5)" instead of 10
which I was hoping.

Is there an easy way to parse a string and turn it into an s-
expression without having to write a complex parser ?

Thanks

Andrew

Jussi Piitulainen

unread,
Nov 12, 2009, 7:28:59 AM11/12/09
to
AndrewW writes:

`read' is the parser you want. You can `read' straight from the file
port, or stream, or whatever it is called nowadays, and I think there
may be a standard way to `read' from a string now, too.

AndrewW

unread,
Nov 12, 2009, 7:55:00 AM11/12/09
to

> `read' is the parser you want. You can `read' straight from the file
> port, or stream, or whatever it is called nowadays, and I think there
> may be a standard way to `read' from a string now, too.

Thanks Jussi,

Works a treat :-

(eval (call-with-input-string "(+ 5 5)" read))

0 new messages