Tree @0.1 (Download .tar.gz)
define-opaque
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
src/define-opaque-0.1.scm
.
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 src
directory.
Basic Instructions
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
called new
that provides a way to initialize a new
instance of the data structure based on some initialization
parameters.
If the above description is unclear, the example programs
in the src
directory may help illuminate the
usage patterns.
TODO
- [ ] is more than one private field supported?
- [ ] support supplying initial values for private fields
Commit History
@0.1
git clone https://git.catseye.tc/define-opaque/
- Merge pull request #1 from cpressey/develop-0.1 Chris Pressey (commit: GitHub) 1 year, 11 months ago
- Rename with version, add documentation and UNLICENSE. Chris Pressey 1 year, 11 months ago
- Simple changes to support a much nicer syntax in usage. Chris Pressey 1 year, 11 months ago
- Refactor the stack datatype to be simpler and easier to use. Chris Pressey 1 year, 11 months ago
- Get passing arguments to the operations working. Chris Pressey 1 year, 11 months ago
- Fix Markdown-typo in README. Chris Pressey 1 year, 11 months ago
- Initial commit of initial work on R5RS `define-opaque` macro. Chris Pressey 1 year, 11 months ago