If all you have is a .js file that loads separately, yes it makes no sense to write it in s-expressions. But javascript also needs to be dynamically generated, especially in event handlers (onload, onclick).
I want to codegenerate js for the same reason I want to codegenerate html: because it's shorter and easier to read when everything isn't in a single string, and because I can eliminate error-prone string escaping. String escaping is perhaps rjs's biggest benefit.
Hmm, what would be a good example? I've been building utilities for modifying urls with javascript before sending out a request. Here's how readwarp prompts you if it thinks you might not be interested in any more stories from say 'Health':
; Add 'group=Health&prune-group='+confirm(msg)
(awhen (borderline-unpreferred-group user doc) ; => returns 'Health'
(addjsarg
(+ default "&group=" it)
; default contains the url params constructed so far
(check-with-user
(+ "I will stop showing any articles about\\n"
" " uncamelcase.it "\\n"
"in this channel. (press 'cancel' to keep showing them)")
"prune-group"))))
Alternatively, couldn't you use JavaScript to dynamically generate itself? You could even write it in sexps if you really wanted to using JS arrays [1]. This is not meant as a critique of your approach but rather as an observation of JS's expressiveness and of the fact that much logic (not all, and maybe not in this particular case) can be implemented client-side or server-side with only subtle differences in the end result.
Yeah I can imagine using js to generate js. But if I'm using arc on the server anyway it doesn't seem to make sense to hand off to a js compiler just to to code-generate js. When I need to generate event handlers I'm within the arc html code-generation. Or am I misunderstanding you?
Nope, you got it. :) You're right it wouldn't make sense in this case where the app is already based in Arc. If you were approaching the project again from scratch though, perhaps there would be a just-as-good implementation path that involves letting JS handle more of the logic.
Yes, or unless you think JS is missing some important feature. Macros come to mind (although I don't know if Ruby can help there).
I'm actually just learning JavaScript now and so far am quite impressed. I'd read before that JS is "lispy" but didn't anticipate it being so true that I could find myself with code like the following:
Just wrote myself a very barebones JS REPL as an exercise [http://evanrmurphy.com/repl.html]. The source is all in that file, just HTML and JS (only tested in Chrome). I can't resist borrowing from Arc wherever I go now, e.g.
function pr () {
for (i in arguments) {
document.write(arguments[i]); }
return arguments; }
is a utility for avoiding the verbosity of "document.write".