Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a Scheme expression to a string

Given an expression '(lambda (x) x) How can I translate this into a string. I thought symbol->string will do the job but no it cant not a symbol.

e.g for a macro to-string: (to-string (lambda(x) x)) this should return >> "(lambda (x) x)"

Any ideas folks Thanks

like image 849
user200654 Avatar asked Nov 02 '09 00:11

user200654


1 Answers

Standard Scheme (at least in the R5RS sense) has no way of doing this, so if you want portable code, you need to walk the structure yourself. Tedious, but not too complicated (even for dotted lists). But if you just want some working version, then you should look in your implementation's manual and search for the way to do this. The answer will almost always be simple, for example, in PLT Scheme you'd use (format "~s" '(lambda ...))

like image 119
Eli Barzilay Avatar answered Sep 24 '22 22:09

Eli Barzilay