43 lines
1.4 KiB
Common Lisp
43 lines
1.4 KiB
Common Lisp
;;;; cl-scopes/shape - really abstract basic data shape definitions.
|
|
|
|
(defpackage :scopes/shape
|
|
(:use :common-lisp)
|
|
(:local-nicknames (:util :scopes/util))
|
|
(:export #:record
|
|
#:head-fields #:head #:head-value #:head-plist
|
|
#:data-fields #:data #:data-value))
|
|
|
|
(in-package :scopes/shape)
|
|
|
|
(defclass record ()
|
|
((head-fields :reader head-fields :initarg :head-fields
|
|
:initform '(:taskid :username) :allocation :class)
|
|
(data-fields :reader data-fields :initarg :data-fields
|
|
:initform nil :allocation :class)
|
|
(head :reader head :initarg :head)
|
|
(data :accessor data :initarg :data :initform nil)))
|
|
|
|
(defmethod initialize-instance :after ((rec record) &key head &allow-other-keys)
|
|
(setf (slot-value rec 'head) (util:rfill (head-fields rec) head)))
|
|
|
|
(defmethod print-object ((rec record) stream)
|
|
(print-unreadable-object (rec stream :type t :identity t)
|
|
(format stream "~s <data ~s>" (head rec) (data rec))))
|
|
|
|
(defun head-value (rec key)
|
|
(elt (head rec) (position key (head-fields rec))))
|
|
|
|
(defun (setf head-value) (val rec key)
|
|
(setf (elt (head rec) (position key (head-fields rec))) val))
|
|
|
|
(defun head-plist (rec)
|
|
(let (pl (hv (head rec)))
|
|
(dolist (hf (head-fields rec))
|
|
(setf pl (cons hf (cons (util:keyword-to-string (pop hv)) pl))))
|
|
pl))
|
|
|
|
(defun data-value (rec key)
|
|
(getf (data rec) key))
|
|
|
|
(defun (setf data-value) (val rec key)
|
|
(setf (getf (data rec) key) val))
|