Please see the comments under the OP. While the question is technically sound (I've needed this exact thing for a REPL I was writing), the comments are perfectly useless, self-entitled and discouraging drivel. Notable example:
> This is an incredibly odd thing to ask
(emphasis theirs). How is this even slightly odd. Are REPLs odd? Of course not.
They ask a question with some weird requirements, people ask why those requirements are in place as it makes it hard to solve, the asker explains why. Everything is good.
If you’re writing a REPL it’s one thing but it does seem like evaluating a string is the kind of thing where most people trying to do it are using the wrong approach.
Please see the comments under the OP. While the question is technically sound (I've needed this exact thing for a REPL I was writing), the comments are perfectly useless, self-entitled and discouraging drivel. Notable example:
> This is an incredibly odd thing to ask
(emphasis theirs). How is this even slightly odd. Are REPLs odd? Of course not.