Steel Bank Common Lisp

BUTLAST counts conses before copying whole list

Reported by Johan Andersson on 2013-10-28
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Low
Unassigned

Bug Description

BUTLAST counts the conses of the argument list before checking if n is zero, in which case the entire list will be copied. The zerop check can be done before counting the conses, as in NBUTLAST. Also, the similar cases of BUTLAST and NBUTLAST can be made clearer.

Regression tests already exist in tests/list.pure.lisp

Paul Khuong (pvk) wrote :

I'll commit this after the freeze.

Thank you!

Changed in sbcl:
status: New → Confirmed
importance: Undecided → Low
assignee: nobody → Paul Khuong (pvk)
status: Confirmed → In Progress

You might want to consider this patch instead. It does BUTLAST and NBUTLAST for (< 0 n) without counting the conses beforehand, by looping with two variables down the list N conses apart.

I'm not sure about the style, the names of the variables or if it's worth the fuss. But there you are.

Paul Khuong (pvk) wrote :

I tried to preserve the logic, but eliminated the counter variable I. It's applied in 498ec57 ([N]BUTLAST perform a single pass over the list).

I also yanked the docstrings out: we try not to duplicate the CLHS.

Thank you!

Changed in sbcl:
status: In Progress → Fix Committed
assignee: Paul Khuong (pvk) → nobody

That's neat! Thanks.

Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers