Proper way to eval scheme code and return the result
Context
I wanted to make a quick Emacs command that inserts the character code (e.g. #\newline) given a key (somewhat like C-q for inserting literal characters).
As such, I was planning on making an Emacs function that write some scheme like (string-ref \" \" 0) and evaluates this to get the result and inserts that into the buffer.
I have looked around trying to figure how this would be done, but haven't figured it out.
(geiser-eval--send/wait "(string-ref \"
\" 0)" 1000)
;; It returns the following
((error (key . retort-syntax)) (output . "$124 = #\\newline
scheme@(guile-user)> ") (debug))
;; So I wrote this
(defun geiser-eval-get-result (code &optional timeout)
(cdr (assoc 'output (geiser-eval--send/wait code timeout))))
;; When run like this...
(geiser-eval-get-result "(string-ref \"
\" 0)" 1000)
;; It returns the following
"$125 = #\\newline
scheme@(guile-user)> "
Of course I could just write more wrapper to parse this out, but I assume this is not the best way to do it.
Looking at the source code for the C-x C-e in Geiser buffers and tracing the geiser-eval--retort-result-str shows that at least some evaluation functions are giving a result entry in the alist, but I'm still not aware of a straightforward way to do this.
I assume some function like this would be useful in general for making more powerful integration functions.
Question
Is there any supported way to send string code for evaluation (without making buffers or other workarounds) and get back the result string?