|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
;; This file:
;; http://anggtwu.net/LISP/tostring1.lisp.html
;; http://anggtwu.net/LISP/tostring1.lisp
;; (find-angg "LISP/tostring1.lisp")
;; Author: Eduardo Ochs <eduardoochs@gmail.com>
;;
;; (defun e () (interactive) (find-angg "LISP/tostring1.lisp"))
;; (find-eev "eev-blinks.el" "find-estruct")
;; (find-es "lisp" "defclass")
;; (find-es "emacs" "cl-print-object")
;; See:
;; (find-angg "LISP/2025-defstruct.lisp")
(defclass mypair ()
((a :initarg :a :initform nil)
(b :initarg :b :initform nil)))
(defun mkmypair (aa bb) (make-instance 'mypair :a aa :b bb))
(defmethod print-object ((p mypair) stream)
(with-slots (a b) p (format stream "~a_~a" a b)))
(mkmypair 22 33) ; -> 22_33
#|
* (eepitch-sly)
* (eepitch-kill)
* (eepitch-sly)
(load "tostring1.lisp")
(describe (mkmypair 22 33))
(mkmypair 22 33)
|#
#|
* (eepitch-sbcl)
* (eepitch-kill)
* (eepitch-sbcl)
(load "tostring1.lisp")
(defvar ab)
(setq ab (mkmypair 22 33))
(setq ab (mkmypair 222 333))
(slot-value ab 'a)
(with-slots (a b) ab (list a b))
(with-slots (a b) ab (format nil "~a_~a" a b))
(defmethod print-object ((p mypair) stream)
(with-slots (a b) p (format stream "~a_~a" a b)))
(mkmypair 4 5)
ab
(princ (pr obj) stream))
(defun prmypair ((p mypair)))
(defclass mypair () ((a :initarg :a) (b :initarg :b)))
(make-instance 'mypair :a 22 :b 33)
(describe (make-instance 'mypair :a 22 :b 33))
(describe (make-instance 'mypair :b 33))
(describe (make-instance 'mypair :a 22))
(describe (make-instance 'mypair))
(with-slots ((aa a) (bb b)) (make-instance 'mypair :a 22 :b 33) (list aa bb))
(with-slots ((aa a) (bb b)) (make-instance 'mypair :b 33) (list aa bb)) ; err
(defmethod print-object ((obj person) stream)
(print-unreadable-object (obj stream :type t)
(with-accessors ((name name)
(lisper lisper))
obj
(format stream "~a, lisper: ~a" name lisper))))
#<STANDARD-CLASS COMMON-LISP-USER::TRIPLE>
CL-USER> (make-instance 'triple :a 1 :b 2 :c 3)
#<TRIPLE {101927F7D3}>
(defclass C () ())
(describe 'C)
(defclass C (a b) ())
(describe 'C)
(defclass C () (a b))
(describe 'C)
(make-instance 'C)
(describe (make-instance 'C))
(describe (make-instance 'C 2 3))
(describe (make-instance 'C :elements 2 3))
(describe 'make-instance)
* (eepitch-sbcl)
* (eepitch-kill)
* (eepitch-sbcl)
(defclass mytriple () (a b c))
(macroexpand '(defclass mytriple () (a b c)))
(describe 'mytriple)
(make-instance 'mytriple)
(make-instance 'mytriple :a 22)
(describe (make-instance 'C 2 3))
(let ((A (make-instance 'my-array :elements '(23 45))))
(print A)) ;; This prints "23_45"
|#