Error with (pop (nthcdr n l))

Bug #1215216 reported by Scott Brown
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Invalid
Undecided
Unassigned

Bug Description

I am using SBCL 1.0.57.0.debian on Ubuntu. It also fails on SBCL 1.0.55.0-abb03f9 on OS X 10.7.

> (setf x '(1 2 3 4 5 6))
( 1 2 3 4 5 6)
> (cdddr x)
(4 5 6)
> (nthcdr 3 x)
(4 5 6)
> (pop (cdddr x))
4
> (setf x '(1 2 3 4 5 6))
( 1 2 3 4 5 6)
;;; This should work the same as (pop (cdddr x))
> (pop (nthcdr 3 x))

; in: POP (NTHCDR 3 X)
; (FUNCALL #'(SETF NTHCDR) #:NEW1009 3 #:X1010)
; ==>
; (SB-C::%FUNCALL #'(SETF NTHCDR) #:NEW1009 3 #:X1010)
;
; caught WARNING:
; The function (SETF NTHCDR) is undefined, and its name is reserved by ANSI CL so
; that even if it were defined later, the code doing so would not be portable.

; (LET* ((#:X1010 X) (#:G1011 (NTHCDR 3 #:X1010)) (#:NEW1009 (CDR #:G1011)))
; (FUNCALL #'(SETF NTHCDR) #:NEW1009 3 #:X1010)
; (CAR #:G1011))
;
; caught WARNING:
; undefined variable: X
;
; compilation unit finished
; Undefined function:
; (SETF NTHCDR)
; Undefined variable:
; X
; caught 2 WARNING conditions

debugger invoked on a UNDEFINED-FUNCTION in thread
#<THREAD "main thread" RUNNING {10036D8BC3}>:
  The function (COMMON-LISP:SETF COMMON-LISP:NTHCDR) is undefined.

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [ABORT] Exit debugger, returning to top level.

("undefined function")
0]

Revision history for this message
Paul Khuong (pvk) wrote :

nthcdr is a function, not an accessor. While an implementation is free to define a SETF expansion for such a function, the standard does not demand it. Moreover, it's not clear to me what would happen in cases like (setf (nthcdr 3 variable-bound-to-nil) 42).

Changed in sbcl:
status: New → Invalid
Revision history for this message
Stas Boukarev (stassats) wrote :

If you want to use setf on nthcdr, use (setf (car (nthcdr ...))) or (setf (cdr (nthcdr ...))).

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.