How to perform `load` from string?

99 views
Skip to first unread message

Ruslan Prokopchuk

unread,
Aug 20, 2017, 5:39:35 AM8/20/17
to chez-scheme
I want to parse and eval Scheme code represented as a string, in the same way as `load` does with files. But I can't find any parser being exposed (which output I could feed `eval` to achieve described result). What is the best way to execute Scheme code represented as string from my Chez Scheme program?

Ruslan Prokopchuk

unread,
Aug 20, 2017, 5:45:42 AM8/20/17
to chez-scheme
Ah, I think `(with-input-from-string "(+ 1 1)" (lambda () (eval (read))))` would do!

Aldo Nicolas Bruno

unread,
Aug 20, 2017, 5:50:15 AM8/20/17
to Ruslan Prokopchuk, chez-...@googlegroups.com
On 20/08/2017 11:45, Ruslan Prokopchuk wrote:
Ah, I think `(with-input-from-string "(+ 1 1)" (lambda () (eval (read))))` would do!

Hi,
what if you have more than 1 expression to evaluate?
this would work:

(call-with-port (open-input-string "(+ 1 2) (+ 3 4)")
        (lambda (p)
          (do ([x (read p) (read p)])
              ((eof-object? x) )
            (display (eval x)) (newline))))

Best regards


On Sunday, August 20, 2017 at 7:39:35 PM UTC+10, Ruslan Prokopchuk wrote:
I want to parse and eval Scheme code represented as a string, in the same way as `load` does with files. But I can't find any parser being exposed (which output I could feed `eval` to achieve described result). What is the best way to execute Scheme code represented as string from my Chez Scheme program?
--
You received this message because you are subscribed to the Google Groups "chez-scheme" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chez-scheme...@googlegroups.com.
To post to this group, send email to chez-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/chez-scheme/a34eb35b-b91e-4c9d-8b2c-9f9963d01061%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Ruslan Prokopchuk

unread,
Aug 21, 2017, 8:56:01 AM8/21/17
to chez-scheme, oven...@pizzahack.eu
Thanks, Aldo, that is what I'm looking for!
Reply all
Reply to author
Forward
0 new messages