bowbow99/xyzzy.ansify — Issue #15: 同じ名前で defstruct & deftype すると...
Author: bowbow99
Created: 2011-10-13 03:09:28+00:00
State: open

(defstruct (foo (:type vector)) a b)
=> #

(defun valid-foo-p (foo)
(and (vectorp foo)
(integerp (foo-a foo))
(integerp (foo-b foo))))
=> valid-foo-p

(deftype foo ()
`(and vector (satisfies valid-foo-p)))
=> foo

;; deftype に従ってる
(ansify::canonicalize-typespec 'foo)
=> (and (array * (*))
(satisfies valid-foo-p))

;; defstruct に従ってる
(ansify::optimize-type-check 'X 'foo)
=> (let ((#1=#:object X))
(and (system:*structurep #1#)
(system:*structure-subtypep (system:*structure-definition #1#)
(get 'foo 'system:structure-definition))))

(setq x (make-foo :a 1 :b 2))
=> #(1 2)

(valid-foo-p x)
=> t

(ansify::typep x 'foo)
=> t

(ansify::check-type x foo)
; Evaluation aborted on `system::check-type-error'
; `x'の値`#(1 2)'はfooではありません

SHA-1: 2c6c92b8e で確認。