[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: detecting uninitialized components of structures.
I need a copy-structure that also copies components (instead of making
them EQ)... Unfortunately, there is no way
to tell if a component is uninitialized without causing an error,
...
The easiest thing to do is to initialize the components somehow:
(define-predicate empty?)
(define (empty id)
(object nil
((print self stream) (format stream "#{Empty~_~s}" id))
((empty? self) t)))
(define-structure-type employee
name
age)
(let ((emp (stype-master employee-stype)))
(set (employee-name emp) (empty employee-name))
(set (employee-age emp) (empty employee-age))
)
If you want the EMPTY? checks to be fast, then you could go
a little lower tech:
(define *empty*
(object nil ((print self stream) (writes stream "#{Empty}"))))
(define-integrable (empty? obj) (eq? obj *empty*))
(let ((emp (stype-master employee-stype)))
(set (employee-name emp) *empty*)
(set (employee-age emp) *empty*)
)
-Norman
-------