11 Encapsulations

An encapsulation is an object that refers to another object, called its content. The Kernel data type encapsulation is encapsulated. Two encapsulations are equal? iff they are eq?. Encapsulations are immutable.

— Applicative: make-encapsulation-type (make-encapsulation-type)

Returns a list of the form (e p? d), where ep?, and d are applicatives, as follows. Each call to make-encapsulation-type returns different applicatives ep?, and d.

  • e is an applicative that takes one argument, and returns a fresh encapsulation with the argument as content. Encapsulations returned on different occasions are not eq?.
  • p? is a primitive type predicate, that takes zero or more arguments and returns true iff all of them are encapsulations generated by e.
  • d is an applicative that takes one argument; if the argument is not an encapsulation generated by e, an error is signaled, otherwise the content of the encapsulation is returned.

That is, the predicate p? only recognizes, and the decapsulator d only extracts the content of, encapsulations created by the encapsulator e that was returned by the same call to make-encapsulation-type.