Detect circular lists in LENGTH

Bug #1171223 reported by Paul Khuong
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Triaged
Wishlist
Unassigned

Bug Description

It would be nice LENGTH of lists could detect circular lists. Currently, we have assembly VOPs to compute LENGTH (… really). It seems to me we could make everything simpler by instead calling to a regular CL function (e.g. %list-length) via a deftransform. There doesn't even have to be a huge penalty to detect circular lists: we can easily call out to CL:LIST-LENGTH once the length is greater than a couple thousand conses.

Paul Khuong (pvk)
description: updated
description: updated
Revision history for this message
Petko Tsikov (tsikov) wrote :

On my machine:

(defparameter lst '(1 2 3)) ; => (1 2 3)
(setf (caddr lst) lst) ; => #1=(1 2 #1#)
(length lst) ; => 3

Seems to me this is the expected behaviour. What do you mean by "LENGTH of lists could detect circular lists"? You are not satisfied with the performance of LENGTH? :)

Revision history for this message
Stas Boukarev (stassats) wrote :

#1=(1 2 #1#) is not a circular list though, #1=(1 2 . #1#) is.

Revision history for this message
Petko Tsikov (tsikov) wrote :

I got it now. Every circular list is improper, thus LENGTH should signal an error, instead of going in an infinite loop.

Revision history for this message
Andrew (andrew.dudash) wrote :

Changed the definition of #'length to use #'list-length and raise an error.

tags: added: review
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.