Print empty/NIL defgeneric/defmethod arglists prettily

Bug #2037131 reported by Artyom Bologov
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
New
Undecided
Unassigned

Bug Description

SBCL is good at printing quoted Lisp forms, and I sometimes use it as a code formatter. It's especially good with DEFUN forms*

(print '(defun foo ()
         (multiple-value-bind (result)
             (+ 1 2 3)
           (+ result 88))))

(DEFUN FOO ()
  (MULTIPLE-VALUE-BIND (RESULT)
      (+ 1 2 3)
    (+ RESULT 88)))

But it doesn't work with defmethod/defgeneric/defclass, especially with their arglists*

(print '(defmethod foo ()
         (multiple-value-bind (result)
             (+ 1 2 3)
           (+ result 88))))

(DEFMETHOD FOO NIL
           (MULTIPLE-VALUE-BIND
            (RESULT) (+ 1 2 3)
            (+ RESULT 88)))

(print '(defclass foo ()
         ((a :initform 4)
          (b :accessor b
             :initarg :b))))

(DEFCLASS FOO NIL
          ((A :INITFORM 4)
           (B :ACCESSOR B :INITARG :B)))

The same thing:
- empty argument/superclass list is printed as NIL.
- The body is off, as if it's a generic list printing.

Would be nice to have arglist/superclasses as () and properly indented body, like

(DEFMETHOD FOO ()
    (MULTIPLE-VALUE-BIND
          (RESULT) (+ 1 2 3)
      (+ RESULT 88)))

(DEFCLASS FOO ()
  ((A :INITFORM 4)
   (B :ACCESSOR B :INITARG :B)))

I understand that this is likely quite an atypical use-case, so not urging or requiring any action. Feel free to close if it's a non-goal.

All the forms are printed with
- *print-right-margin* set to 40
- on SBCL 2.3.5
- on machine uname Linux paranoidal 6.4.16 #1 SMP PREEMPT_DYNAMIC 1 x86_64 GNU/Linux
- with *features*
(CFFI-FEATURES:FLAT-NAMESPACE
 CFFI-FEATURES:X86-64
 CFFI-FEATURES:UNIX :CFFI
 CFFI-SYS::FLAT-NAMESPACE
 ALEXANDRIA::SEQUENCE-EMPTYP :QUICKLISP
 :ASDF3.3 :ASDF3.2 :ASDF3.1 :ASDF3
 :ASDF2 :ASDF :OS-UNIX
 :NON-BASE-CHARS-EXIST-P :ASDF-UNICODE
 :ARENA-ALLOCATOR :X86-64 :GENCGC
 :64-BIT :ANSI-CL :COMMON-LISP :ELF
 :IEEE-FLOATING-POINT :LINUX
 :LITTLE-ENDIAN
 :PACKAGE-LOCAL-NICKNAMES
 :SB-CORE-COMPRESSION :SB-LDB
 :SB-PACKAGE-LOCKS :SB-THREAD
 :SB-UNICODE :SBCL :UNIX)

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.