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

destructuring-bind

vlad-km opened this issue · comments

commented

JSCL

CL-USER> (destructuring-bind (name . bind) (cons :name 2) 
...           (values name bind)) 
... 
ERROR: CDR called on non-list argument
CL-USER> 

SBCL

CL-USER> (destructuring-bind (name . bind) (cons :name 1)
                    (values name bind))
:NAME
1
CL-USER> 

Obviously, the problem is not hot, if no one has encountered it.

Good catch.

Obviously, the problem is not hot, if no one has encountered it.
I think it is quite important! and you did find it :-)

I guess we didn't notice that because I tend not to use (a . b) while restructuring, but &rest instead.

Conveniently, the lambda-list.lisp implementation works fine on other implementations too. So if you try the same example in the (jscl) destructuring-bind running on SBCL, we get more information:

JSCL> (!destructuring-bind (name . bind) (cons :name 2) 
        (values name bind))

gives:

The value
  2
is not of type
  LIST
   [Condition of type TYPE-ERROR]

...

Backtrace:
 0: (VALIDATE-REQVARS (:NAME . 2) 1)

The stacktrace can be useful to fix it.

The first error it encounters is that we use validate-reqvars to validate the minimum length of the list, which uses length, but it fails with improper lists.

I suspect there is also an error while parsing the lambda-list, because of this example:

JSCL> (lambda-list-restvar (parse-destructuring-lambda-list '(bind . name )))
(NAME)
JSCL> (lambda-list-restvar (parse-destructuring-lambda-list '(bind &rest name)))
NAME

It is a nice issue. @vlad-km , if you or someone else wants to give it a try. Otherwise I'll have a look in a few days 👍

commented

I plan to release a system update in a couple of weeks - types, condition and structure.
I will make an announcement of updates in the coming days.
This error will wait. I use &rest too.

👍 no problem, I'll take care of it then. Looking forward for those updates!