<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 &lt;matthias@ccs.neu.edu&gt; 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&nbsp;</div><div><br /></div><div>&nbsp;(define (hi person) ...)&nbsp;</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&nbsp;</div><div><br /></div><div>&nbsp;#lang htdp/bsl&nbsp;</div><div><br /></div><div>(and perhaps we will supply a way to create this line for young kids who can't type well).&nbsp;</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. &nbsp;E.g., take a BSL module containing<blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div><font color="#000099">;; hi : String -&gt; 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">;;&nbsp;</font><span style="color:rgb(0,0,153);font-family:'courier new',monospace">mod-path-&gt;evaluator : path module-path -&gt; (any -&gt; any)</span></div><div>
<font face="courier new, monospace" color="#000099">(define (mod-path-&gt;evaluator p replacement-lang)</font></div><div><font face="courier new, monospace" color="#000099">&nbsp; (parameterize ([read-accept-reader #t])</font></div>
<div><font face="courier new, monospace" color="#000099">&nbsp; &nbsp; (let ([mod (read (open-input-file p))])</font></div><div><font face="courier new, monospace" color="#000099">&nbsp; &nbsp; &nbsp; (match mod</font></div><div><font face="courier new, monospace" color="#000099">&nbsp; &nbsp; &nbsp; &nbsp; [(list 'module name lang body ...)</font></div>
<div><font face="courier new, monospace" color="#000099">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(make-module-evaluator</font></div><div><font face="courier new, monospace" color="#000099">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; `(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>&nbsp;</b>defines all the&nbsp;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? &nbsp;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 /> &nbsp;Racket Users list:<br /> &nbsp;<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>