jscl-project / jscl

A Lisp-to-JavaScript compiler bootstrapped from Common Lisp

Home Page:https://jscl-project.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Format issue (LOOP undefined)

jetmonk opened this issue · comments

I'm not sure this is a bug, because FORMAT isn't supported according to document, but the nature of the error suggests it could be a bug:

;; on web demo
CL-USER> (format nil "~,4F" pi)
ERROR: Function 'LOOP' undefined

I have to say, I'm amazed that a Lisp this complete is running in JS! Very nice! Thank you!

It is indeed a bug. Thanks for reporting!

Format support is very limited. some directives should work ~A, ~S, ~D. But this issue is caused because format used the infinite loop variant: (loop ...code...). Which was built-in into the compiler before loop support was introduced.

Now loop is fully supported, but it is defined after format. Changing the order should fix it, but it might require some adjustments to avoid circular dependencies. I'll give it a try. 🙂

I pushed an update.

it does not support ~F still, but this should be a small improvement:

CL-USER> (format nil "~,4F" pi)
WARNING: #\F is not implemented yet, using ~S instead
"3.1415927"

I would be nice to try to add a compliant format already. 🙂

Given the complexity of format, have you considered trying to appropriate SBCL's public domain format code?

Surely. Probably sbcl's implementation is pretty complex though. There could be simpler ones that fit JSCL better.

But yes, quasiquote, loop and clos were all adapted from other implementations so it is very likely we should do the same with format