Name:
Anonymous
2018-12-17 1:29
;;--------------------------------------------------------------------
;;-- Types
;; slot-number type
(defun within-slot-number-rangep (n)
(not (or (< n 0) (> n 255))))
(deftype slot-number ()
`(and fixnum (satisfies within-slot-number-rangep)))
;; vitality type
(defun within-vitality-rangep (v)
(not (or (< v -1) (> v 65535))))
(deftype vitality ()
`(and fixnum (satisfies within-vitality-rangep)))
;; field type
(deftype field ()
`(or fixnum function))
(deftype field-application ()
`(and function))
;;--------------------------------------------------------------------
;;-- Structures
;; slot structure
(defstruct slot
(number 0 :type index)
(field #'identity :type field)
(vitality 10000 :type vitality))
Name:
Anonymous
2018-12-19 17:08
>>5deftype can take parameters and can run arbitrary functions. it returns a type that Common Lisp checks at compile time.