Plaster
New
List
Login
common-lisp
default
anonymous
2024.05.31 14:13:25
(in-package #:gbbopen-user) (define-unit-class message () ((text :initarg :text) (sender :link (user messages) :singular t) (timestamp :initarg :timestamp)) (:dimensional-values (timestamp :point timestamp)) (:initial-space-instances (erc messages))) (define-unit-class user () ((name :initarg :name) (messages :link (message sender :singular t))) (:dimensional-values (name (:element equal) name)) (:initial-space-instances (erc users))) (defmethod print-instance-slots ((user user) stream) (call-next-method) (print-instance-slot-value user 'name stream)) (make-space-instance '(erc)) (make-space-instance '(erc messages) :dimensions (dimensions-of 'message)) (make-space-instance '(erc users) :dimensions (dimensions-of 'user)) (snippets/erc-logs:with-open-erc-log-file (stream "/home/death/.erc/logs/#commonlisp.txt") (loop for entry = (snippets/erc-logs:read-erc-log-entry stream) until (null entry) when (eq (car entry) :message) do (destructuring-bind (&key time nick message &allow-other-keys) (cdr entry) (let ((user (or (find-instances 'user '(erc users) `(is name ,nick)) (make-instance 'user :name nick)))) (make-instance 'message :timestamp time :sender user :text message))))) ;; in the repl ;; GBBOPEN-USER> :dsbb ;; ;; Space Instance Contents ;; -------------- -------- ;; ERC Empty ;; MESSAGES 26278 instances (26278 MESSAGE) ;; USERS 397 instances (397 USER) ;; ;; Unit Class Instances ;; ---------- --------- ;; MESSAGE 26,278 ;; STANDARD-SPACE-INSTANCE 3 ;; USER 397 ;; --------- ;; 26,678 instances ;; GBBOPEN-USER> (find-instances 'user 't '(is name "_death")) ;; (#<USER 64 "_death">) ;; GBBOPEN-USER> (subseq (messages-of (first *)) 0 3) ;; (#<MESSAGE 26278> #<MESSAGE 26250> #<MESSAGE 26249>) ;; GBBOPEN-USER> :di 26278 ;; Message #<MESSAGE 26278> ;; Instance name: 26278 ;; Space instances: ((ERC MESSAGES)) ;; Dimensional values: ;; TIMESTAMP: 940 ;; Non-link slots: ;; TEXT: "gbbopen has the concept of unit classes, whose instances are automatically put on the blackboard.. you can then query for these instances" ;; TIMESTAMP: 940 ;; Link slots: ;; SENDER: #<USER 64 "_death"> ;; GBBOPEN-USER>
Raw
Annotate
Repaste
Edit