[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A new field (hidden-field)




I've added the inaccessible hidden field to <optional-field> as well as to
<automatic-field>, and changed <specification> according to the change.

(define-lambda-object stack
  (name 'stack)                                                          ;optional read-only field
  ('stack '())                                                                 ;optional hidden-field
  (',original-stack stack)                                            ;automatic hidden-field
  (`,pop (if (null? stack)                                              ;automatic virtual-field
      (error 'stack "null stack (original stack)" stack original-stack)
      (let ((s (car stack))) (set! stack (cdr stack)) s)))
  (,push (lambda (s) (set! stack (cons s stack)))))  ;automatic read-only field

(define stack (make-stack 'stack (list 'sunflower)))
((stack 'push) 'rose)
((stack 'push) 'lily)
(stack 'pop)                           => lily
(stack 'pop)                           => rose
(stack 'pop)                           => sunflower
(stack 'pop)                           => error: stack: null stack (original stack) () (sunflower)
(stack 'name)                        => stack
(stack 'stack)                         => error: define-lambda-object: absent field stack
(stack 'original-stack)           => error: define-lambda-object: absent field original-stack


--
Joo