Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the interface Reference Manual, generated automatically by Declt version 3.0 "Montgomery Scott" on Tue Dec 22 13:53:05 2020 GMT+0.
• Introduction | What interface is all about | |
• Systems | The systems documentation | |
• Files | The files documentation | |
• Packages | The packages documentation | |
• Definitions | The symbols documentation | |
• Indexes | Concepts, functions, variables and data types |
INTERFACE ========= By Robert Smith 1. Introduction This system contains an implementation of interfaces and implementations. They're sometimes called protocols in other languages. Broadly speaking, an "interface" is some collection of function "prototypes" that a valid implementation must implement. For example, something called a "stack" must implement stack creation, pushing, peeking, and popping. The notion of interfaces and implementations aid the distinction between data structures and different implementations of that data structure. This was perhaps pioneered by Modula-3, and became a significant part of other languages like Standard ML and OCaml. In all of the aforementioned languages, interfaces can actually contain more than just functions, such as types and values. Haskell typeclasses are also a form of interface and implementation. They are very general and are even parametric. One way to accomplish the notion of interfaces and implementations in Lisp is to use some "abstract class" and make several (final) subclasses of that class. The interface, in this case, is the abstract class and a collection of generic functions. The implementation would be the final subclass along with method definitions. For example: (defclass stack () ()) (defgeneric make-stack (impl)) (defgeneric stack-push (impl s x)) (defgeneric stack-pop (impl s)) (defgeneric stack-peek (impl s)) (defclass list-stack (stack) ()) (defmethod make-stack ((impl list-stack)) nil) (defmethod stack-push ((impl list-stack) s x) (cons x s)) (defmethod stack-pop ((impl list-stack) s) (cdr s)) (defmethod stack-peek ((impl list-stack) s) (car s)) This is mostly sufficient, though Lisp makes no guarantee that a class will have any set of methods defined for it. (One could perhaps use the MOP for this.) One can "optimize" implementations by conflating the notion of an implementation with the actual data structure being implemented, and make it a part of the implementation class. In this case, we could have a slot in LIST-STACK holding the list. Since methods are not tied to classes, this implementation allows one to have a class implement several methods. Also, it is entirely possible to do away with the superclass; that is a formality tying all implementations to a particular interface with a name. As I understand, this basic notion is taken to the extreme with Fare's Lisp Interface Library (http://www.cliki.net/lisp-interface-library). In this system, however, we take a different approach entirely. Instead of using a class to represent interfaces and implementations, we have a structure whose slots are the implementation functions. The name of the structure (which decides what slots it has) is the interface, and the implementation is the actual slot values. It is cumbersome, however, to use an interface by accessing slots all of the time. Instead, we define functions---which correspond to the slot names---which access the slots of an implementation and pass the arguments to it. In doing this, there's no dispatch on type required, just access on the slots of the structure. It also forces data structures and the interface to be completely disjoint entities. 2. Example (define-interface stack () (make-stack (&rest r)) (push-stack (s x)) (peek-stack (s)) (pop-stack (s))) (define-implementation list-stack (stack) :make-stack (lambda (&rest r) r) :push-stack (lambda (s x) (cons x s)) :peek-stack (lambda (s) (car s)) :pop-stack (lambda (s) (cdr s))) (define-implementation vector-stack (stack) :make-stack (lambda (&rest r) (let ((length (length r))) (make-array length :adjustable t :fill-pointer length :initial-contents r))) :push-stack (lambda (s x) (vector-push-extend x s) s) :peek-stack (lambda (s) (aref s (1- (length s)))) :pop-stack (lambda (s) (vector-pop s) s)) ;;; CL-USER> (pop-stack vector-stack ;;; (push-stack vector-stack ;;; (make-stack vector-stack 1 2 3) ;;; 5)) ;;; #(1 2 3) ;;; CL-USER> (pop-stack list-stack ;;; (push-stack list-stack ;;; (make-stack list-stack 1 2 3) ;;; 5)) ;;; (1 2 3) 3. Performance This implementation has been measured to be between 10% and 30% faster than the classes approach described above. See the file interface-bench.lisp. 4. Other notes The package also has a handy utility function called CALLING-FORM. It solves the following problem: Consider a function F with a lambda list (L...). How can we write a function G (defun G (L...) ??>) such that calls to G are precisely equivalent to F? We can use (calling-form 'f '(L...)) which will produce code which is suitable for the definition of G.
Next: Files, Previous: Introduction, Up: Top [Contents][Index]
The main system appears first, followed by any subsystem dependency.
• The interface system |
Robert Smith <quad@symbo1ics.com>
BSD 3-clause (See LICENSE)
A system for defining interfaces.
interface.asd (file)
Files are sorted by type and then listed depth-first from the systems components trees.
• Lisp files | ||
• Static files |
Next: Static files, Previous: Files, Up: Files [Contents][Index]
• The interface.asd file | ||
• The interface/package.lisp file | ||
• The interface/interface.lisp file |
Next: The interface/package․lisp file, Previous: Lisp files, Up: Lisp files [Contents][Index]
interface.asd
interface (system)
Next: The interface/interface․lisp file, Previous: The interface․asd file, Up: Lisp files [Contents][Index]
Previous: The interface/package․lisp file, Up: Lisp files [Contents][Index]
package.lisp (file)
interface (system)
interface.lisp
Previous: Lisp files, Up: Files [Contents][Index]
• The interface/license file |
Previous: Static files, Up: Static files [Contents][Index]
interface (system)
LICENSE
Next: Definitions, Previous: Files, Up: Top [Contents][Index]
Packages are listed by definition order.
• The interface package |
package.lisp (file)
intf
common-lisp
Definitions are sorted by export status, category, package, and then by lexicographic order.
• Exported definitions | ||
• Internal definitions |
Next: Internal definitions, Previous: Definitions, Up: Definitions [Contents][Index]
• Exported macros | ||
• Exported functions |
Next: Exported functions, Previous: Exported definitions, Up: Exported definitions [Contents][Index]
interface.lisp (file)
Define an interface whose name is NAME and list of options are OPTIONS. (Currently, no options are supported.) The body of the definition should be a list of "interface specifications". An interface specification is:
* A list containing a function name as the first element and the
lambda list as the second element.
* A symbol representing a constant value.
interface.lisp (file)
Previous: Exported macros, Up: Exported definitions [Contents][Index]
Given an ordinary lambda list LAMBDA-LIST and a FUNCALLable FUNCTION-FORM, construct a form which calls FUNCTION-FORM on all of the arguments specified by LAMBDA-LIST.
interface.lisp (file)
Previous: Exported definitions, Up: Definitions [Contents][Index]
• Internal functions | ||
• Internal structures |
Next: Internal structures, Previous: Internal definitions, Up: Internal definitions [Contents][Index]
interface.lisp (file)
Construct the calling form with the function form FUNCTION-FORM and the arglist ARGLIST.
interface.lisp (file)
interface.lisp (file)
interface.lisp (file)
interface.lisp (file)
Extend the arglist ARGLIST with the arguments ARGS. Creates a new arglist.
interface.lisp (file)
interface.lisp (file)
interface.lisp (file)
interface.lisp (file)
interface.lisp (file)
interface.lisp (file)
interface.lisp (file)
interface.lisp (file)
Create an arglist identical to the arglist ARGLIST, except specifying that it must use APPLY.
interface.lisp (file)
Previous: Internal functions, Up: Internal definitions [Contents][Index]
interface.lisp (file)
structure-object (structure)
arglist-args (function)
(setf arglist-args) (function)
arglist-use-apply (function)
(setf arglist-use-apply) (function)
Previous: Definitions, Up: Top [Contents][Index]
• Concept index | ||
• Function index | ||
• Variable index | ||
• Data type index |
Next: Function index, Previous: Indexes, Up: Indexes [Contents][Index]
Jump to: | F I L S |
---|
Jump to: | F I L S |
---|
Next: Variable index, Previous: Concept index, Up: Indexes [Contents][Index]
Jump to: | (
A C D E F I M |
---|
Jump to: | (
A C D E F I M |
---|
Next: Data type index, Previous: Function index, Up: Indexes [Contents][Index]
Jump to: | A S U |
---|
Index Entry | Section | ||
---|---|---|---|
| |||
A | |||
args : | Internal structures | ||
| |||
S | |||
Slot, args : | Internal structures | ||
Slot, use-apply : | Internal structures | ||
| |||
U | |||
use-apply : | Internal structures | ||
|
Jump to: | A S U |
---|
Previous: Variable index, Up: Indexes [Contents][Index]
Jump to: | A I P S |
---|
Jump to: | A I P S |
---|