scheme_eval_string equivalent for racket-cs

28 views
Skip to first unread message

Dan Dexter

unread,
Dec 16, 2020, 11:55:07 AM12/16/20
to Racket Users
I'm porting existing code that is embedding racket and I'm going from racket-bc to racket-cs.

In racket-bc, the code is calling scheme_eval_string() and scheme_eval_string_all().

I don't see a direct replacement for these functions in racket-cs.  Based on the embedding example in the docs, I'm currently using the following:

void EvalString(const std::string& str)
{
    ptr expr = to_bytevector(str.c_str());
    expr = Scons(Sstring_to_symbol("open-input-bytes"), Scons(expr, Snil));
    expr = Scons(Sstring_to_symbol("read"), Scons(expr, Snil));
    expr = Scons(Sstring_to_symbol("eval"), Scons(expr, Snil));
    racket_eval(expr);
}

Would this be equivalent?  And also equivalent to scheme_eval_string_all() ?
--< Dan >--

Matthew Flatt

unread,
Dec 17, 2020, 10:42:56 PM12/17/20
to Dan Dexter, Racket Users
That will work if your namespace has `open-input-bytes`, etc. It might
be better to use `racket_dynamic_require` to specifically get the
functions from `racket/base`, applying each with `racket_apply`.

A better strategy might be to have a function that combines all of
these pieces in an embedded module, and then there's just one function
to get and call. In general, that fits better with Racket CS, which
really wants as much as possible to be on the Racket side.

Matthew
Reply all
Reply to author
Forward
0 new messages