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

Re: Internal defines/reference implementations



I don't think the problem with internal record definitions is in
implementation complexity - it's in generativity. If you define
a new record type inside a procedure, it is natural to expect
the same record type each time you enter the procedure; otherwise
the objects you created before won't be recognized by record
type predicate:

;; sample enumeration protocol for nonempty sequences:
(define (enumerate-stuff state) ;=> obj, {next-state or #f}
    (define-record-type my-enum-state ...)
    (if (eq? state #f) 
        ;; start enumeration
        (values obj1 (make-my-enum-state ...))
        ;; continue enumeration
        (let ((next-state (if (has-next? state) (next-state state) #f)))
            (values (state-obj state) next-state))))

;; display all objects:
(let loop ([state #f]) 
   (receive (obj next-state) (enumerate-stuff state)  
      (display obj)
      (if next-state (loop next-state))))

This imaginary enumeration protocol uses opaque state
objects existing outside the dynamic scope of enumerate-stuff
invokation. To recognize them, my-enum-state should define
the same record type each time enumerate-stuff is called.