<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><blockquote type="cite"><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); margin-top: 0pt; margin-right: 0pt; margin-bottom: 0pt; margin-left: 0.8ex; padding-left: 1ex; position: static; z-index: auto; "><div style=""><div>Hi YC,</div><div><br></div>There are two current, well documented ways of generating Javascript source using Scheme code:<div><br></div><div><span style="white-space: pre;">        <a href="http://planet.plt-scheme.org/package-source/dherman/javascript.plt/9/2/planet-docs/javascript/index.html" target="_blank">http://planet.plt-scheme.org/package-source/dherman/javascript.plt/9/2/planet-docs/javascript/index.html</a></span></div> <div><span style="white-space: pre;"></span><span style="white-space: pre;">        <a href="http://planet.plt-scheme.org/package-source/untyped/mirrors.plt/2/2/planet-docs/mirrors/index.html" target="_blank">http://planet.plt-scheme.org/package-source/untyped/mirrors.plt/2/2/planet-docs/mirrors/index.html</a></span><br> <div><br></div><div>To my knowledge, neither of these libraries compile actual Scheme into Javascript, but they both have a parenthetic syntax for writing Javascript code. So, for example, in Mirrors you can do stuff like this:</div> <div><br></div><div><font face="Monaco" size="3"><span style="font-size: 13px;">&nbsp;&nbsp; &nbsp;(js (alert ,(string-append "Hello " "world"))</span></font></div><div><br></div><div>I use Mirrors with jQuery quite a lot;</div> <div><br></div><div><font face="Monaco" size="3"><span style="font-size: 13px;">&nbsp;&nbsp; &nbsp;(js (!dot ($ "#mybutton")</span></font></div><div><font face="Monaco" size="3"><span style="font-size: 13px;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(click (function () (alert "Hi")))))</span></font></div> <div></div></div></div></blockquote><div><br>Cool - this approach seems simple and effective - are you able to write more complicated code structures such as if/while/case? I envision for those you currently write in javascript? (javascript is not bad, of course).<font class="Apple-style-span" color="#000000"><font class="Apple-style-span" color="#144FAE"><br></font></font></div></div></blockquote><br></div><div>Yes you can. See the docs for more info.</div><div><br></div><div>I&nbsp;should&nbsp;explain&nbsp;that&nbsp;the&nbsp;two&nbsp;libraries&nbsp;above&nbsp;are&nbsp;very&nbsp;similar, and that Dave Herman wrote most of the code in both cases:</div><div><br></div><div>&nbsp;&nbsp;- they both have DSLs that expand into a Javascript AST;</div><div>&nbsp;&nbsp;- they both use Dave's Javascript AST representation;</div><div>&nbsp;&nbsp;- they both use Dave's pretty printing algorithms to format the JS into a string.</div><div><br></div><div>Mirrors JS is based on an old experiment of Jay's. It's really a thin veneer over Dave's code. Dave's parenthetical syntax came after Mirrors, and is IMO a little nicer (see Sections 5.2 and 5.3 of his docs).</div><div><br></div><div>However, all that said, Mirrors provides unique handy things that (AFAIK) other libraries don't provide. These things include JS begin statements and multi-statement splicing:</div><div><br></div><div>&nbsp;&nbsp; &nbsp;(js&nbsp;,@(for/list ([i (in-range 10)])</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (js (alert "Number")</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(alert ,i))))</div><div><br></div><div>raw blocks:</div><div><br></div><div>&nbsp;&nbsp; &nbsp;(js #&lt;&lt;ENDJS</div><div>alert("A");</div><div>ENDJS</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;)</div><div><br></div><div>custom expanders (a la define-match-expander) and so on.</div><div><br></div><div>-- Dave</div><div><br></div></body></html>