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

Debugging ?

mmontone opened this issue · comments

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!

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.

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.

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!

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

@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.

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.