R7RS functional iterators over containers
Go to file
Peter McGoron 089a03166a test multi character string 2024-12-28 23:06:50 -05:00
tests test multi character string 2024-12-28 23:06:50 -05:00
.gitignore .gitignore 2024-12-28 11:30:28 -05:00
Makefile convert to chicken 2024-12-28 12:01:47 -05:00
README.md refactor iterators to be closure objects 2024-12-28 21:27:24 -05:00
container-iterator.egg refactor string exceptions 2024-12-28 22:51:33 -05:00
mcgoron.iterator.base.scm refactor exceptions to be less verbose 2024-12-28 22:29:28 -05:00
mcgoron.iterator.base.sld refactor exceptions to be less verbose 2024-12-28 22:29:28 -05:00
mcgoron.iterator.exceptions.scm refactor exceptions to be less verbose 2024-12-28 22:29:28 -05:00
mcgoron.iterator.exceptions.sld refactor exceptions to be less verbose 2024-12-28 22:29:28 -05:00
mcgoron.iterator.list.scm refactor string exceptions 2024-12-28 22:51:33 -05:00
mcgoron.iterator.list.sld more list work 2024-12-28 22:47:45 -05:00
mcgoron.iterator.srfi.128.scm refactor iterators to be closure objects 2024-12-28 21:27:24 -05:00
mcgoron.iterator.srfi.128.sld refactor iterators to be closure objects 2024-12-28 21:27:24 -05:00
mcgoron.iterator.string.scm refactor string exceptions 2024-12-28 22:51:33 -05:00
mcgoron.iterator.string.sld refactor string exceptions 2024-12-28 22:51:33 -05:00

README.md

Container Iterators

Container iterators are a generic way to access elements in a linearly ordered collection, such as strings, vectors, and ordered sets.

"Iterators" are in the style of C++: they can (potentially) go forward, backward, have start and end limits, etc. Not all operations are available for a concrete iterator.

Design

The iterators in this library are polymorphic and may only implement a subset of the possible operations on an iterator, but Scheme has no standard way to make extensible polymorphic functions. Instead of tying the library to a specific implementations's object system, the iterators are closures wrapped in record types. The iterators don't use inheritance or any message passing: they are more like Go interfaces or Rust traits than the usual Scheme object system.

Iterator types are created using

(define-iterator-constructor (cstr cstr-args ...)
  ((method-name . method-formal) method-body ...)
  ...)

This creates a procedure cstr that when called creates an iterator whose type is the cstr name as a symbol. Each method is defined as a lambda that takes method-formal as arguments and evaluates method-body with cstr-args in scope.

To invoke the method, use

(define-invocation name args ...)

This defines a procedure name that takes an iterator and invokes the method with the same name in the iterator with the number of args in args.

This object system could probably be ported to CLOS-style object systems with a judicious enough use of macros. Properly implementing the bound identifiers may require non-hygenic macros.