<html><head/><body><html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><br><div class="gmail_quote">Matthias Felleisen <matthias@ccs.neu.edu> wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div><br /></div><div>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</div><div><br /></div><div>p.s. To think of </div><div><br /></div><div> (define (hi person) ...) </div><div><br /></div><div>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 </div><div><br /></div><div> #lang htdp/bsl </div><div><br /></div><div>(and perhaps we will supply a way to create this line for young kids who can't type well). </div><div><br /></div><div><br /></div><br /><div><div>On Nov 1, 2012, at 6:57 PM, Jordan Johnson wrote:</div><br class="Apple-interchange-newline" /><blockquote type="cite">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<blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div><font color="#000099">;; hi : String -> String</font></div><div><font color="#000099">(define (hi person) (string-append "Hi, " person "!"))</font></div></blockquote><div>and evaluate it in a different language.</div>
<div><br /></div><div>This is what I've come up with so far, which seems to do the trick:</div><div><br /></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font face="courier new, monospace" color="#000099">(require racket/sandbox)</font></div>
<div><font face="courier new, monospace" color="#000099">;; </font><span style="color:rgb(0,0,153);font-family:'courier new',monospace">mod-path->evaluator : path module-path -> (any -> any)</span></div><div>
<font face="courier new, monospace" color="#000099">(define (mod-path->evaluator p replacement-lang)</font></div><div><font face="courier new, monospace" color="#000099"> (parameterize ([read-accept-reader #t])</font></div>
<div><font face="courier new, monospace" color="#000099"> (let ([mod (read (open-input-file p))])</font></div><div><font face="courier new, monospace" color="#000099"> (match mod</font></div><div><font face="courier new, monospace" color="#000099"> [(list 'module name lang body ...)</font></div>
<div><font face="courier new, monospace" color="#000099"> (make-module-evaluator</font></div><div><font face="courier new, monospace" color="#000099"> `(module ,name ,replacement-lang ,@body))]))))</font></div>
</blockquote><div><br /></div><div>The explicitness of destructuring and rebuilding of the module bugs me a bit, but assuming that <font face="courier new, monospace" color="#000099">replacement-lang</font><b> </b>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?</div>
<div><br /></div><div>That said, it's still pretty neat to see how easily this was done once I found the necessary parts.</div><div><br /></div><div>jmj</div><div><br /></div>
____________________<br /> Racket Users list:<br /> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br /></blockquote></div><br /></blockquote></div></body></html></body></html>