A Visit to a Sad Planet

综合编程 2017-04-18

One of the things that always irked me about my EPUB reader
was that part of it is written in JavaScript, simply because that’s the only way one can script a browser view these days. I’ve always wanted to give the SPOCK
compiler a try to see how well it does compared to ClojureScript, so this project gave me the perfect chance to cure me of delusions. After an evening, I got it running, it took me a few more evenings to iron out bugs introduced by the conversion and add a new bugfix. Here’s a list of observations made in that time:

  • Both versions are about the same size, with the Scheme version being a bit shorter (which is mostly closing parentheses not going on a separate line). I’d expect a greater difference in favor of the Scheme version if I had any noteworthy business logic embedded into this, but alas.
  • Debugging got significantly harder as there is no REPL, no source maps integration and no debugger for the Scheme code. I’ve had to do with classic printf
    -Debugging, except that it looked more like
    (%inline "console.log" (jstring (string-append
    "Foo " (number->string

  • While there is documentation (which includes a few working examples), it isn’t clear how to use the compiler to its fullest abilities. I’ve resorted to compiling all kinds of code and staring at the compiler output to see what works and what doesn’t. This experimentation revealed that you’ll want to use %inline
    for most interop, with a bit of dot syntax for property access. ClojureScript beats SPOCK easily in this aspect, including its #js
    reader macro and conversion macros from/to JS data structures.
  • Error reporting is extremely basic, with some errors being silent and merely preventing code from executing any further.
  • The supported language is restricted to R5RS with a few useful macros and JS-specific helpers. In other words, while you might manage compiling other Scheme libraries to JavaScript, you’re better off writing your own helpers as needed.
  • Tooling is simple and quick. Recompiling code is instantaneous, it’s easy to see what part of your own code maps to the generated parts. This is the only benefit I see in SPOCK over ClojureScript.

To summarize, if you want maximum comfort and features, go for ClojureScript. The price you pay for it is significant friction while developing, but other than that it’s pretty advanced. Personally I think I’ll stay with vanilla JavaScript for my other toy projects to keep things as simple and painless as possible.

I predict that Guile Emacs won’t lead to a significant increase in packages written in Scheme for similar reasons. Much like in browsers, the majority of Emacs Lisp usage doesn’t have complex business logic and follows the principle of practicality over purity. Perhaps it’s different for big projects like Magit or Evil, but even these cases are doubtful to me, simply because they have higher priorities than speculative rewrites that might as well kill the project. I could keep rambling about my reasons for this assessment, but that is better left for a separate blog post…

责编内容by:Emacs Ninja (源链)。感谢您的支持!


When arguments are mutable I’ve found this weird behavior of the arguments inside a function while p...
Creating RESTful APIs With JEC — Part 1: JavaScrip... This article is the first of a series focusing on building RESTful APIs over...
有意思的前端函数面试题 if(a == 1 && a == 2 && a == 3){ console.log("我走进来了"); } va...
为什么a=”abc” 不等于 a=new String(“abc... 显而易见 a="abc" typeof a //string b=new String("abc") typeof b // object a==b //t...
JavaScript学习笔记(十二)——箭头函数(Arrow Function)... 在学习廖雪峰前辈的JavaScript教程中,遇到了一些需要注意的点,因此作为学习笔记列出来,提醒自己注意! 如果大家有需要,欢迎访问前辈的博客 ...