jscl-project / jscl

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

Debugging ? #438

Open mmontone opened 2 years ago

mmontone commented 2 years ago

Hi,

is there a way for me to debug things when something goes wrong ? Like, get a backtrace or something.

I'm trying this at JSCL repl:

CL-USER> (defun ilt-apropos (string) 
...   (let (found) 
...     (dolist (package (list-all-packages)) 
...       (do-external-symbols (sym package) 
...     (when (search string (symbol-name sym) :test 'equalp) 
...       (push sym found)))) 
...     found))
ILT-APROPOS

But I get:

CL-USER> (ilt-apropos "list") 
... 
ERROR: this is undefined

It works in SBCL for example, so it is not that my function is buggy.

Thanks!

mmontone commented 2 years ago

I realize there's no EQUALP in JSCL, so I'm trying with STRING=, but error still:

CL-USER> (defun ilt-apropos (string)  
... ...   (let (found)  
... ...     (dolist (package (list-all-packages))  
... ...       (do-external-symbols (sym package)  
... ...     (when (search string (symbol-name sym) :test #'string=)  
... ...       (push sym found))))  
... ...     found))
ILT-APROPOS
CL-USER> (ilt-apropos "LIST") 
... 
ERROR: Variable ... is unbound.

So, it'd still be nice if there's a way for me to debug things.

mmontone commented 2 years ago

My bad, that last version is working. I was getting those ... because of copying pasting at the REPL.

But still, any tips on debugging are welcomed.

davazp commented 2 years ago

I don't really have specific tips, other general recommendation like trying your code often to know what is most likely to have caused the issue or narrow down cases to the simplest code that gets you the error or adding some print calls 🙂

Improvements in this area would be great!

davazp commented 2 years ago

I think I found the reason for the bad error message. I'll create a pull request!

davazp commented 2 years ago

@mmontone I added a detailed description of how I went to fix the issue in the PR description at #439 .

It's not really any debugging tip but, hopefully it helps a bit! It would be great to have proper stacktraces.

I guess the natural step is trying to have sourcemap support in JSCL, but that might require some work.

mmontone commented 2 years ago

Thank you!

I've tried by sending errors to console. I can visualize some error object and a stack there, but doesn't help much.

The easiest for now I think it is to make errors as informative as possible, as you've done with your fix. That's not always the case in JSCL.