From: Stas Boukarev Date: Fri, 13 Apr 2012 11:38:53 +0000 (+0400) Subject: pprint: Make sure that lists like (loop . 10) can be printed. X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=9ebf496afbad179facaa8db5d45e5a807b1c002c;p=sbcl.git pprint: Make sure that lists like (loop . 10) can be printed. pprint signaled an error when called on improper lists with a car being a symbol from CL (loop, macrolet, flet, and some others). --- diff --git a/NEWS b/NEWS index a4137d0..141efbd 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,8 @@ changes relative to sbcl-1.0.56: use of NCONC in MAKE-LEXENV. (lp#924276) * bug fix: ENSURE-DIRECTORIES-EXIST now works when *default-pathname-defaults* contains NAME or TYPE components. + * bug fix: PPRINT couldn't print improper lists with CARs being some symbols + from CL package, e.g. (loop . 10). * documentation: ** improved docstrings: REPLACE (lp#965592) diff --git a/src/code/pprint.lisp b/src/code/pprint.lisp index f499bfb..f542878 100644 --- a/src/code/pprint.lisp +++ b/src/code/pprint.lisp @@ -1142,7 +1142,8 @@ line break." (consp (cdr list)) (cddr list) ;; Filter out (FLET FOO :IN BAR) names. - (not (eq :in (third list)))) + (and (consp (cddr list)) + (not (eq :in (third list))))) (funcall (formatter "~:<~^~W~^ ~@_~:<~@{~:<~^~W~^~3I ~:_~/SB!PRETTY:PPRINT-LAMBDA-LIST/~1I~:@_~@{~W~^ ~_~}~:>~^ ~_~}~:>~1I~@:_~@{~W~^ ~_~}~:>") stream @@ -1266,7 +1267,9 @@ line break." (defun pprint-defmethod (stream list &rest noise) (declare (ignore noise)) - (if (consp (third list)) + (if (and (consp (cdr list)) + (consp (cddr list)) + (consp (third list))) (pprint-defun stream list) (funcall (formatter "~:<~^~W~^ ~@_~:I~W~^ ~W~^ ~:_~/SB!PRETTY:PPRINT-LAMBDA-LIST/~1I~@{ ~_~W~}~:>") @@ -1373,7 +1376,7 @@ line break." (declare (ignore noise)) (destructuring-bind (loop-symbol . clauses) list (declare (ignore loop-symbol)) - (if (or (null clauses) (consp (car clauses))) + (if (or (atom clauses) (consp (car clauses))) (pprint-spread-fun-call stream list) (pprint-extended-loop stream list)))) diff --git a/tests/pprint.impure.lisp b/tests/pprint.impure.lisp index 038af4d..4e6d8a3 100644 --- a/tests/pprint.impure.lisp +++ b/tests/pprint.impure.lisp @@ -278,5 +278,18 @@ (assert (eq orig (pprint-dispatch 'some-symbol))) (assert (not (eq alt orig))))) +(with-test (:name :pprint-improper-list) + (let* ((max-length 10) + (stream (make-broadcast-stream)) + (errors + (loop for symbol being the symbol in :cl + nconc + (loop for i from 1 below max-length + for list = (cons symbol 10) then (cons symbol list) + when (nth-value 1 (ignore-errors (pprint list stream))) + collect (format nil "(~{~a ~}~a . 10)" (butlast list) symbol))))) + (when errors + (error "Can't PPRINT imporper lists: ~a" errors)))) + ;;; success