[plt-scheme] ajax and plt

From: Dave Gurnell (d.j.gurnell at gmail.com)
Date: Fri Jul 3 03:41:13 EDT 2009

> Hi YC,
> There are two current, well documented ways of generating Javascript  
> source using Scheme code:
> 	http://planet.plt-scheme.org/package-source/dherman/javascript.plt/9/2/planet-docs/javascript/index.html
> 	http://planet.plt-scheme.org/package-source/untyped/mirrors.plt/2/2/planet-docs/mirrors/index.html
> 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:
>     (js (alert ,(string-append "Hello " "world"))
> I use Mirrors with jQuery quite a lot;
>     (js (!dot ($ "#mybutton")
>               (click (function () (alert "Hi")))))
> 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).

Yes you can. See the docs for more info.

I should explain that the two libraries above are very similar, and  
that Dave Herman wrote most of the code in both cases:

   - they both have DSLs that expand into a Javascript AST;
   - they both use Dave's Javascript AST representation;
   - they both use Dave's pretty printing algorithms to format the JS  
into a string.

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  

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:

     (js ,@(for/list ([i (in-range 10)])
                (js (alert "Number")
                     (alert ,i))))

raw blocks:

     (js #<<ENDJS

custom expanders (a la define-match-expander) and so on.

-- Dave

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090703/1df6f043/attachment.html>

Posted on the users mailing list.