This is an attempt to write a macro in R5RS Scheme that defines opaque data structures. It is based on the third example given in Information Hiding in Scheme.
It is not intended to be suitable for production use. It is, however, intended to properly hide the details of the created data structure, by preventing access to it by any means other than via the defined operations.
The macro is defined in
The idea is that you'd just copy it into your project and
(load "define-opaque.scm") where you need it. For usage,
see the demo files also in the
The arguments to the
define-opaque macro are
- the name of the opaque data structure that will result (this name will be visible globally)
- the name of a function which creates a new instance of the data structure (this name will be visible only to the operations)
- a list of names for the data items used internally (these names will be visible only to the operations)
- a list of operations. Each operation is a 2-element list, consisting of its name, and a lambda expression giving its implementation.
The opaque data structure that results is a Scheme function. When it is called, the first argument must be the name of an operation; the remainder of the arguments are passed to
Typically, the opaque data structure that results
is treated as a "protoype", and one defines an operation
new that provides a way to initialize a new
instance of the data structure based on some initialization
If the above description is unclear, the example programs
src directory may help illuminate the
- [ ] is more than one private field supported?
- [ ] support supplying initial values for private fields
git clone https://git.catseye.tc/define-opaque/
- Merge pull request #1 from cpressey/develop-0.1 Chris Pressey (commit: GitHub) 7 months ago
- Rename with version, add documentation and UNLICENSE. Chris Pressey 7 months ago
- Simple changes to support a much nicer syntax in usage. Chris Pressey 8 months ago
- Refactor the stack datatype to be simpler and easier to use. Chris Pressey 8 months ago
- Get passing arguments to the operations working. Chris Pressey 8 months ago
- Fix Markdown-typo in README. Chris Pressey 8 months ago
- Initial commit of initial work on R5RS `define-opaque` macro. Chris Pressey 8 months ago