curry-compose-reader-macros icon indicating copy to clipboard operation
curry-compose-reader-macros copied to clipboard

Printer that prints readably when readtable is c-c-r-m

Open pfdietz opened this issue 5 years ago • 3 comments

The symbol :|[| does not print readably when the readtable is c-c-r-m. Add functionality to fix this, and any other incompatibility between reading and printing. Ideally, this should be specified along with the readtable, and be composable like readtables. This may require update to named-readtables. There is unfortunately no standard way to merge pprint dispatch tables.

pfdietz avatar Oct 27 '20 14:10 pfdietz

Can you provide a minimal example of what is going wrong currently and how you would like to see it behave?

eschulte avatar Oct 30 '20 15:10 eschulte

Example:

(defpackage :example
  (:use :cl :named-readtables :curry-compose-reader-macros))

(in-package :example)

(defun round-trip (e)
  (let ((*package* (find-package :example))
        (*readtable* (find-readtable :curry-compose-reader-macros)))
    (read-from-string (with-output-to-string (s)
                        (format s "~s" e)))))

;; (round-trip :|[|) ==> reader error

pfdietz avatar Oct 30 '20 17:10 pfdietz

I don't know if there is a portable way to do this. The problem is that the lisp printer isn't escaping [.

EXAMPLE> (prin1 '|(|)
|(|
|(|
EXAMPLE> (prin1 '|[|)
[
[

Looking into SBCL's implementation there is a note in the implementation of output-symbol which says

                        ;; Hmm. Should these depend on what characters
                        ;; are actually escapes in the readtable ?
                        ;; (See similar remark at DEFUN QUOTE-STRING)

and the decision is ultimately made by the symbol-quotep function.

eschulte avatar Oct 30 '20 18:10 eschulte