jscl-project / jscl

A Lisp-to-JavaScript compiler bootstrapped from Common Lisp
https://jscl-project.github.io
GNU General Public License v3.0
876 stars 108 forks source link

feature testing not work as intended at compile time #474

Open VitoVan opened 1 year ago

VitoVan commented 1 year ago
(defpackage :common-lisp-user)

#+jscl
(defun hello ()
  (format t "Hello, yes JSCL ~%"))

#-jscl
(defun hello ()
  (format t "Hello, no JSCL ~%"))

(hello)

This piece of code should output "Hello, yes JSCL", right?

But after compiling, it output "Hello, no JSCL".

sbcl --load jscl.lisp --eval '(jscl:bootstrap)' --eval '(jscl:compile-application (list "feature-test.lisp") "main.js")' --eval '(quit)'
imagen

Is this a bug?

I wish to use the same Lisp code to compile on different platforms, like SBCL and ECL and JSCL, how to detect JSCL at compile time?

VitoVan commented 1 year ago

Here is a workaround:

sbcl --load jscl.lisp --eval '(jscl:bootstrap)' \
     --eval '(pushnew :jscl *features*)' \
     --eval '(jscl:compile-application (list "feature-test.lisp") "main.js")' \
     --eval '(quit)'

I don't know if it has any side-effects, but it seems to be working.