Using macros readers, it's possible to interpret JavaScript, and have it compiled just like normal Common Lisp code. Hence getting the benefits of Lisp implementations, notably their performance. Which would mean having native performance in the browser, without cheating.

Would it be technically possible to build this for the browser? I'm mainly worried about the DOM bindings.

  • It'd be ok until the first eval(). JavaScript needs a smart tracing JIT to be efficient, any form of static compilation, no matter how sophisticated, will fail for such a dynamic language. – SK-logic Jul 5 '13 at 8:06
  • I don't get why eval() would hurt. It'd just compile the eval string, no? Or there's something I'm not understanding. – Florian Margaine Jul 5 '13 at 8:14
  • eval has to assume that its argument is dynamic. This means that you cannot JIT-compile and optimize into the eval; every time the eval statement is called, the argument has to be parsed and JIT-compiled, and the eval call forms a boundary for things like CSE and other optimizations. – tdammers Jul 5 '13 at 8:42
  • String is not known in compile time and generated dynamically. – SK-logic Jul 5 '13 at 8:42
  • @SK-logic after thinking about it, Lisp has eval too. So it'd use its runtime engine to execute it. eval would be slow, but it's to be expected anyway. – Florian Margaine Jul 5 '13 at 9:02

Sorry, but your assumption is wrong. Lisp is nice and all, but it isn't magic dynamic performance pixie dust.

Compiling/running something that looks sort of like basic JavaScript is one thing. But it is not what is needed.

Add in what is necessary to have said JavaScript have variables that autoconvert between integer, floating point, and string representations according to the spec. Add in the variable lookup method that JavaScript uses. (Variables are looked up in a series of scopes, starting with the current function call.) Add in the object model that JavaScript uses. Continue through the spec, and you will keep on making things slower and slower.

Once you're done, even though you started with Lisp, you've simply got another implementation of a JavaScript runtime that is slow for all the reasons that any other is. It could be faster or slower than existing implementations. Given the optimization effort that has gone into those implementations, it likely will be slower by a wide margin.

At that point, figuring out whether to finish writing a browser in Lisp, or whether to load Lisp into a browser and apply the right JavaScript hooks is up to you. But your performance assumptions are wrong.

Now looking at this, you could be tempted to say that it would be nice to create a new language that can be dynamic and performs better. It would be, but there is a chicken and egg problem. Unless all browsers have it, nobody will use it. Unless people use it, browsers won't write it. This is solvable, for instance look at HTML5 Canvas. But it seems easier to solve if it is targeted at a known pain point, see HTML5 Canvas. Ripping out all of JavaScript for something else does not seem to be an easy thing to do. (Microsoft tried back at the dawn of the web age. When was the last time you saw VBScript in the wild?)

  • Well, I guess you're right. Silly silly dreams. – Florian Margaine Jul 5 '13 at 17:29

Common Lisp is not the fastest in terms of execution speed when it comes to implementation of other programming languages by compiling it to Common Lisp or even interpreting it in Common Lisp.

Even Common Lisp has basically three different speed ranges:

  • the normal Lisp language. It can be compiled efficiently, but there are inherent things which makes it less fast than C and other low-level languages. For example it needs a lot of runtime checks and runtime decisions.

  • a low-level Lisp language. This can be compiled to very efficient code. But here we need and exploit performance hints, type declarations, type inference, code inlining and more.

  • a high-level object system (CLOS), which is hard to compile to efficient code

But Common Lisp is still used to implement languages. Sometimes for research and exploration.

For example there was an implementation of Javascript in Common Lisp. It was written by Netscape to explore Javascript semantics:


But as you can see that implementation is not simple and no, 'reader macros' are not of much help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.