jscl icon indicating copy to clipboard operation
jscl copied to clipboard

destructuring-bind

Open vlad-km opened this issue 4 years ago • 5 comments

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.

vlad-km avatar Nov 22 '20 12:11 vlad-km

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.

davazp avatar Nov 22 '20 13:11 davazp

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

davazp avatar Nov 22 '20 13:11 davazp

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 👍

davazp avatar Nov 22 '20 13:11 davazp

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.

vlad-km avatar Nov 22 '20 15:11 vlad-km

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

davazp avatar Nov 22 '20 19:11 davazp