Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (in-package #:uwu)
- (defclass node ()
- ((properties :accessor properties :initform (make-hash-table :test #'equal))
- (links-from :accessor links-from :initform ())
- (links-to :accessor links-to :initform ())
- (nickname :accessor nickname :initarg :nickname)
- (printer :accessor printer :initarg :printer :initform #'nickname)))
- (defmethod print-object ((node node) stream)
- (format stream "~a" (funcall (printer node) node)))
- (defun create-node (&optional (name nil))
- (make-instance 'node :nickname name))
- (defclass link ()
- ((a :accessor a :initarg :a) ;from
- (b :accessor b :initarg :b)
- (properties :accessor properties :initform (make-hash-table :test #'equal)))) ;to
- (defmethod link ((a node) (b node))
- (let ((link (make-instance 'link :a a :b b)))
- (push link (links-from a))
- (push link (links-to b))
- link))
- (defmethod link-child ((a node) (b node))
- (let ((link (link a b)))
- (setf (gethash "type" (properties link)) "child")
- link))
- (defmethod create-child ((parent node) (name string))
- (let ((child (create-node name)))
- (link-child parent child)
- child))
- (defmethod read-property ((node node) property)
- (gethash property (properties node)))
- (defconstant *prototype-prototype*
- (create-node "prototype"))
- (defconstant *context-prototype*
- (create-child *prototype-prototype* "context"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement