[racket] Call racket with long code from racket

From: Rodolfo Carvalho (rhcarvalho at gmail.com)
Date: Wed Sep 14 11:53:43 EDT 2011

As other people already said, this way of doing things is not the most "safe
and beautiful" way of getting what you need done.
If "long-code" is really long and important, I suggest investigating other

As Eli pointed out there are many weird conventions to pay attention
depending on your shell.
When you pass the string with quotes as in your example, I get an error like
this: /bin/sh: Syntax error: EOF in backquote substitution
Because bash is waiting for a second `.

Using a string would also make it difficult to write strings, because you'd
need to escape the double-quotes "\"this is a string\"" (and they will most
likely conflict with your shell).

The code below will show how the external code will be called and the
stdout/stderr (so you can see what's going wrong).

Using a quoted form instead of a string hides the problem of having ` and '
and instead use quasiquote and quote.


Rodolfo Carvalho

#lang racket
(define external-code (format  "/opt/racket/bin/racket -e \" ~a \""
                                  (require mzlib/defmacro)
                                  (define-macro (my-when
                                                 test . body)
                                    `(if ,test (begin , at body) '()))
                                  (my-when #t '(5 6 7)))))

(displayln external-code)

  (let* ([p (process external-code)]
         [stdout (first p)]
         [stderr (fourth p)])
    (map port->string (list stdout stderr)))

On Tue, Sep 13, 2011 at 08:22, Niitsuma Hirotaka <
hirotaka.niitsuma at gmail.com> wrote:

> > You could try something like this:
> > #lang racket
> > (require racket/system)
> > (display (port->string (car (process (format "racket -e '~a' " '(+ 2
> 3))))))
> That does not work in the following case
>  (display (port->string (car (process    (format  "racket -e \" ~a \" "
>                                                "
>                                                (require mzlib/defmacro)
>                                                (define-macro (my-when
> test . body)`(if ,test (begin , at body) '() ))
>                                 (my-when #t '(5 6 7))
>                                                "
>                                                )))))
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110914/c679b6ac/attachment.html>

Posted on the users mailing list.