Advertisement
Guest User

Untitled

a guest
May 25th, 2023
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.37 KB | None | 0 0
  1. (in-package #:uwu)
  2.  
  3. (defclass node ()
  4.   ((properties :accessor properties :initform (make-hash-table :test #'equal))
  5.    (links-from :accessor links-from :initform ())
  6.    (links-to :accessor links-to :initform ())
  7.    (nickname :accessor nickname :initarg :nickname)
  8.    (printer :accessor printer :initarg :printer :initform #'nickname)))
  9.  
  10. (defmethod print-object ((node node) stream)
  11.   (format stream "~a" (funcall (printer node) node)))
  12.  
  13. (defun create-node (&optional (name nil))
  14.   (make-instance 'node :nickname name))
  15.  
  16. (defclass link ()
  17.   ((a :accessor a :initarg :a) ;from
  18.    (b :accessor b :initarg :b)
  19.    (properties :accessor properties :initform (make-hash-table :test #'equal)))) ;to
  20.  
  21.  
  22. (defmethod link ((a node) (b node))
  23.   (let ((link (make-instance 'link :a a :b b)))
  24.     (push link (links-from a))
  25.     (push link (links-to b))
  26.     link))
  27. (defmethod link-child ((a node) (b node))
  28.   (let ((link (link a b)))
  29.     (setf (gethash "type" (properties link)) "child")
  30.     link))
  31.  
  32. (defmethod create-child ((parent node) (name string))
  33.   (let ((child (create-node name)))
  34.     (link-child parent child)
  35.     child))
  36.  
  37. (defmethod read-property ((node node) property)
  38.   (gethash property (properties node)))
  39.  
  40. (defconstant *prototype-prototype*
  41.   (create-node "prototype"))
  42.  
  43. (defconstant *context-prototype*
  44.   (create-child *prototype-prototype* "context"))
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement