|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
;; This file:
;; http://anggtwu.net/elisp/2025-modern-prints-output.el.html
;; http://anggtwu.net/elisp/2025-modern-prints-output.el
;; (find-angg "elisp/2025-modern-prints-output.el")
;; Author: Eduardo Ochs <eduardoochs@gmail.com>
;;
;; See: (find-angg "ORG/2025-modern.org")
;; (find-angg "elisp/2025-modern-advice.el")
;; (find-angg "elisp/2025-modern-reset.el")
;; (find-angg "elisp/emacsconf2024.el")
;;
;; «.lambdas» (to "lambdas")
;; «.advice» (to "advice")
;; «.class» (to "class")
;; Four ways of `cl-print'ing
;; interpreted-function objects.
;; «lambdas» (to ".lambdas")
;; Let's create an object `o', with:
(defun foo (a b) "Docstr" (interactive (list 2 3)) a (+ a b))
(setq o (symbol-function 'foo))
;; In older Emacses `o' is this list - an "old-style lambda":
(lambda (a b) "Docstr" (interactive (list 2 3)) a (+ a b))
;; In newer Emacses `o' is a "vector-like lambda", that
;; DOESN'T HAVE A CANONICAL PRINTED REPRESENTATION!!!
;; In newer Emacses we have:
;; (prin1-to-string o) ->
#[(a b) (a (+ a b)) nil nil "Docstr" (list 2 3)]
;;
;; (cl-prin1-to-string o) ->
#f(lambda (a b) :dynbind "Docstr" (interactive (list 2 3)) a (+ a b))
;; But `cl-prin1-to-string' is configurable!
;; For example, in the "named plist" style we have:
;; (cl-prin1-to-string o) ->
(interpreted-function
:args (a b)
:code (a (+ a b))
:consts nil
:stackdepth nil
:docstring "Docstr"
:iform (list 2 3))
;; «advice» (to ".advice")
;; Three ways of `cl-print'ing advice objects.
;; Let's define the object `adt-o' with:
(defun adt-insert (&rest args) (insert (format "\n;; --> %S" args)))
(defun adt-1 (o) (adt-insert ':1 o) (list 'adt-1 o))
(defun adt-2 (o) (adt-insert ':2 o) (list 'adt-2 o))
(defun adt-3 (o) (adt-insert ':3 o) (list 'adt-3 o))
(advice-add 'adt-2 :before 'adt-1)
(advice-add 'adt-2 :after 'adt-3)
(setq adt-o (symbol-function 'adt-2))
;; Newer Emacs `cl-print' the object `o' as:
#f(advice adt-3
:after #f(advice adt-1
:before #f(lambda (o)
:dynbind (adt-insert ':2 o) (list 'adt-2 o))))
;; But we can redefine how advices
;; are `cl-print'ed, and get:
#f(advice
:car adt-3
:how :after
:cdr #f(advice
:car adt-1
:how :before
:cdr (lambda (o) (adt-insert ':2 o) (list 'adt-2 o))
:props nil)
:props nil)
;; named, but using `:how' instead of `:how•':
#f(advice
:car adt-3
:how
:after
:cdr #f(advice
:car adt-1
:how
:before
:cdr #f(lambda (o)
:dynbind (adt-insert ':2 o) (list 'adt-2 o))
:props nil)
:props nil)
;; «class» (to ".class")
#s(cl-structure-class
:name cl-structure-class
:docstring "The type of CL structs descriptors."
:parents (#s(cl-structure-class
:name cl--class
:docstring "Abstract supertype of all type descriptors."
:parents (#s(cl-structure-class
:name cl-structure-object
:docstring "The root parent of all \"normal\" CL structs"
:parents (#s(built-in-class
:name record
:docstring "Abstract type of objects with slots."
:parents (#s(built-in-class
:name atom
:docstring "Abstract supertype of anything but cons cells."
:parents (#s(built-in-class
:name t
:docstring "Abstract supertype of everything."
:parents nil
:slots nil
:index-table nil))
:slots nil
:index-table nil))
:slots nil
:index-table nil))
:slots []
:index-table #<hash-table eq 0/0 0x18365b465ff4 ...>
:tag cl-structure-object
:type nil
:named nil
:print t
:children-sym cl-struct-cl-structure-object-tags))
:slots [#s(cl-slot-descriptor :name name :initform nil :type symbol :props nil)
#s(cl-slot-descriptor :name docstring :initform nil :type string :props nil)
#s(cl-slot-descriptor :name parents :initform nil :type (list-of cl--class) :props nil)
#s(cl-slot-descriptor :name slots :initform nil :type (vector cl-slot-descriptor) :props nil)
#s(cl-slot-descriptor :name index-table :initform nil :type hash-table :props nil)]
:index-table #<hash-table eq 5/5 0x18365b46af0c ...>
:tag cl--class
:type nil
:named nil
:print t
:children-sym cl-struct-cl--class-tags))
:slots [#s(cl-slot-descriptor :name name :initform nil :type symbol :props nil)
#s(cl-slot-descriptor :name docstring :initform nil :type string :props nil)
#s(cl-slot-descriptor :name parents :initform nil :type (list-of cl--class) :props nil)
#s(cl-slot-descriptor :name slots :initform nil :type (vector cl-slot-descriptor) :props nil)
#s(cl-slot-descriptor :name index-table :initform nil :type hash-table :props nil)
#s(cl-slot-descriptor :name tag :initform nil :type symbol :props nil)
#s(cl-slot-descriptor :name type :initform nil :type (memq (vector list)) :props nil)
#s(cl-slot-descriptor :name named :initform nil :type boolean :props nil)
#s(cl-slot-descriptor :name print :initform nil :type boolean :props nil)
#s(cl-slot-descriptor :name children-sym :initform nil :type symbol :props nil)]
:index-table #<hash-table eq 10/10 0x18365b6b04f0 ...>
:tag cl-structure-class
:type nil
:named nil
:print t
:children-sym cl-struct-cl-structure-class-tags)