Detect circular lists in LENGTH

Bug #1171223 reported by Paul Khuong on 2013-04-21
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
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) on 2013-04-21
description: updated
description: updated
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? :)

Stas Boukarev (stassats) wrote :

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

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.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers