[racket] Evaluating a module with an unintended language

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Thu Nov 1 22:11:12 EDT 2012

I can't think of another way. But I am also wondering why you'd want to run a program written in language L in language K. -- Matthias

p.s. To think of 

 (define (hi person) ...) 

as a program is wrong. You should look at the file proper where you will see the extra lines that your reader accept 'throws away'. In the near future, we will ask students to write 

 #lang htdp/bsl 

(and perhaps we will supply a way to create this line for young kids who can't type well). 

On Nov 1, 2012, at 6:57 PM, Jordan Johnson wrote:

> Looking at some of the recent tutorials on building and using languages in Racket, I was prompted to wonder what I'd have to do in order to take an existing module (in its own file) and evaluate it with a language other than the one it is specified to use, without modifying the module's original source file.  E.g., take a BSL module containing
> ;; hi : String -> String
> (define (hi person) (string-append "Hi, " person "!"))
> and evaluate it in a different language.
> This is what I've come up with so far, which seems to do the trick:
> (require racket/sandbox)
> ;; mod-path->evaluator : path module-path -> (any -> any)
> (define (mod-path->evaluator p replacement-lang)
>   (parameterize ([read-accept-reader #t])
>     (let ([mod (read (open-input-file p))])
>       (match mod
>         [(list 'module name lang body ...)
>          (make-module-evaluator
>           `(module ,name ,replacement-lang , at body))]))))
> The explicitness of destructuring and rebuilding of the module bugs me a bit, but assuming that replacement-lang defines all the forms used in the module's intended language, is this more or less the way that those of you who have built plenty of languages in Racket would do it?  Any suggested improvements?
> That said, it's still pretty neat to see how easily this was done once I found the necessary parts.
> jmj
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20121101/29f3c16d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4373 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20121101/29f3c16d/attachment.p7s>

Posted on the users mailing list.