The introductions to the Scheme reports begin: There is an important language paradigm of OO languages that is essentially missing in Scheme. I know no common name for this feature but some of the capability community call it ‘synergy’ on which I pontificate here. The sealer-unsealer pattern was first described in Morris’s 1973 Protection in Programming Languages. Jonathan Rees shows how to implement the sealer-unsealer pattern of Scheme 48 in official R5RS primitives. See this. Upon this pattern the other synergy patterns can be efficiently defined. Alas, as Rees points out, his implementation upon R5RS is fatally flawed for anything but demos because the abstracted data can never be garbage collected. Just now (2016 May) I think that this may solve the problem well enough.

Not many know of Morris’ sealers but the pattern is implicit in C++ and other OO languages; it is the ability of the code of a class to simultaneously access the abstracted data of multiple instances of the class. For many purposes Scheme’s closures serve to abstract data, even in multiple instantiations. Suppose, however, I want to abstract how I represent a complex number with reals. I need to define addition of two complex numbers and that requires simultaneously accessing the representations internal to each. There is no place to put code to bring the abstracted reals together to add them in order to produce the abstracted sum, while respecting the abstraction. C++ does this so easily that no one notices. Rees shows how to do this but you never regain the storage, and each new addition is incrementally slower.

This simple set abstraction in Scheme serves well when synergy is not needed but if we want to form the union of two sets, the pattern breaks down. For instance my transcription of the OCaml set module cannot abstract the set representation as it must bring together sets to form their union etc. OCaml abstracts the innards with the same syntactic ease as C++. Unlike C++ the abstraction is secure.

See this Scheme module for a somewhat satisfactory solution in Scheme.

Rees proposes the sealer creator as a primitive and I propose the safe. I imagine the safe is just a bit simpler but either can be used to efficiently define the other or to define eq?, whereas eq? defines neither the sealer nor the safe efficiently. Scheme already has eq? and this means that no insecurities are introduced by adding the sealer or the safe.

An older note with other patterns.