This library provides a way to define an interface (a set of procedures with defined names and parameter count), define interface’s implementation(s), and call interface method with specific implementation reference.
While generally interface abstraction is less needed compared to statically typed and / or object oriented languages, it can be handy in certain contexts, such as when implementing “Ports and Adapters” (also known as “Hexagon”) architecture, which was the main motivation for the creation of this library.
Report issues at https://github.com/arvyy/r7rs-interface/issues
Interface is defined with
(define-interface interface-implementation-constructor method-signature ...)
method-signature is either
(method-name arg ...)
(method-name arg ... . rest)
(define-interface foo (bar arg1 arg2))
interface-implementation-constructor is bound to syntax for constructing implementation of this interface, which shall be used so
(interface-implementation-constructor (method-signature method-body) ...)
For example (using
foo interface from above),
(define foo-impl (foo ((bar arg1 arg2) (list arg1 arg2))))
Finally, to invoke interface’s method, call it by supplying implementation instance as a first parameter
(display (bar foo-impl 1 2)) ;; should show "(1 2)"
During construction of implementation instance, the syntax verifies that