[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.3.5 Implementing collections

The minimum requirements of the collection class implementation is as follow:

This makes iterator methods such as map, for-each, find and filter to work.

In order to make the constructive methods (e.g. map-to to create your collection), you have to implement call-with-builder method as well. Note that call-with-builder method must work a sort of class method, dispatched by class, rather than normal method dispatched by instance. In Gauche, you can implement it by using a metaclass. Then the minimal code will look like this:

 
(define-class <your-collection-meta> (<class>) ())

(define-class <your-collection> (<collection>)
 (...) ;; slots
 :metaclass <your-collection-meta>)

(define-method call-with-iterator
    ((coll <your-collection>) proc . options)
  ...
  )

(define-method call-with-builder
     ((coll <your-collection-meta>) proc . options)
  ...
  )

Optionally, you can overload other generic functions to optimize performance.



This document was generated by Ken Dickey on November, 28 2002 using texi2html