changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / lisp/lib/obj/id.lisp

changeset 387: 8252ee515756
parent: a3b65a8138ac
author: Richard Westhaver <ellis@rwest.io>
date: Thu, 30 May 2024 18:31:53 -0400
permissions: -rw-r--r--
description: db and readtables
1 ;;; lib/obj/id.lisp --- IDs
2 (in-package :obj/id)
3 
4 (defclass id ()
5  ((id :initarg :id :initform 0 :accessor id :type fixnum)))
6 
7 (defgeneric reset-id (obj)
8  (:documentation "Reset the id slot of SELF to 0.")
9  (:method ((obj standard-object)) (setf (id obj) 0))
10  (:method ((obj t)) 0))
11 
12 (defgeneric update-id (obj)
13  (:documentation "Update the id slot of SELF.")
14  (:method ((obj standard-object)) (setf (id obj) (hash-object obj)))
15  (:method ((obj t)) (hash-object obj)))
16 
17 (defgeneric make-id (kind)
18  (:documentation "Allocate a new ID object of a specified KIND.")
19  (:method ((kind (eql nil)))
20  (declare (ignore kind))
21  (make-instance 'id))
22  (:method ((kind (eql t)))
23  (declare (ignore kind))
24  (make-instance 'id :id most-positive-fixnum)))
25 
26 (defmethod print-object ((obj id) stream)
27  (print-unreadable-object (obj stream :type "ID")
28  (format stream "~A" (id obj))))
29 
30 (defclass id-factory () ())
31 
32 (defgeneric identify (self)
33  (:documentation "Return the identity of object SELF - usually meant for objects which don't
34 specialize on ID but should still sometimes return an ID."))