[Sbcl-help] weird assert behaviour

1 view
Skip to first unread message

Jacek Podkanski via Sbcl-help

unread,
Aug 24, 2023, 11:43:25 AM8/24/23
to sbcl...@lists.sourceforge.net
Hi,

I have this function for experiment with generating xml from a tree.

(defun read-tags (tree)
  (destructuring-bind (tag attrs next) (serapeum:take 3 tree)
    (assert (typep tag 'keyword))
    (assert (or (typep attrs 'nil)
                (typep attrs 'cons)))
    (assert (evenp (length attrs)))
    (assert (member next '(:content :children)))

    attrs
    ))

the problem is that the assertion does not pick up the odd length attrs list. Is this an SBCL error or I do not understand Lisp?

XML> (assert (evenp (length '(:id))))
; Evaluation aborted on #<SIMPLE-ERROR "~@<The assertion ~S failed~:[.~:; ~
;                                            with ~:*~{~S = ~S~^, ~}.~]~:@>" {100B890BD3}>.
XML> (read-tags '(:interface '(:id) :content))
'(:ID)
XML> (lisp-implementation-version)
"2.3.7.144-9f746524e"
XML>

Douglas Katzman via Sbcl-help

unread,
Aug 24, 2023, 12:05:05 PM8/24/23
to Jacek Podkanski, sbcl...@lists.sourceforge.net
In the example you supplied, 'attrs' becomes (quote (:id)) which is indeed a 2-list.  So why did you write it with an extra quote in there - is that how it will be used, or is it a mistake in the test case?

_______________________________________________
Sbcl-help mailing list
Sbcl...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sbcl-help

Michał "phoe" Herda via Sbcl-help

unread,
Aug 24, 2023, 2:11:08 PM8/24/23
to Jacek Podkanski, sbcl...@lists.sourceforge.net

The value of ATTRS is '(ID), which is (QUOTE (ID)), which is a list of length 2, which is an even number.

You probably want to remove the inner quote.

Reply all
Reply to author
Forward
0 new messages