Next: srfi ilists quotation, Previous: srfi ilists rationale, Up: srfi ilists [Index]
A set of general criteria guided the design of the SRFI-1 library that underlies this library. They are reproduced here.
List–filtering procedures such as ifilter
or idelete
do
not disorder lists. Elements appear in the answer list in the same
order as they appear in the argument list. This constrains
implementation, but seems like a desirable feature, since in many uses
of lists, order matters. (In particular, disordering an association
list is definitely a bad idea.)
Contrariwise, although the sample implementations of the list–filtering procedures share longest common tails between argument and answer lists, it is not part of the spec.
Because ilists are an inherently sequential data structure (unlike, say,
vectors), inspection procedures such as ifind
, ifind-tail
,
ifor-each
, iany
and ievery
commit to a
left-to–right traversal order of their argument list.
However, constructors, such as ilist-tabulate
and the mapping
procedures (iappend-map
, ipair-for-each
,
ifilter-map
, imap-in-order
), do not specify the dynamic
order in which their procedural argument is applied to its various
values.
Predicates return useful true values wherever possible. Thus
iany
must return the true value produced by its predicate, and
ievery
returns the final true value produced by applying its
predicate argument to the last element of its argument list.
No special status is accorded Scheme’s built–in equality predicate.
Any functionality provided in terms of eq?
, eqv?
,
equal?
is also available using a client–provided equality
predicate.
These procedures are not generic as between ordinary pairs/lists and immutable pairs/lists; they are specific to immutable lists. Like Olin, I prefer to keep the library simple and focused. However, there are a few conversions between mutable and immutable lists provided.
Scheme does not properly have a list type, just as C does not have a string type. Rather, Scheme has a binary–tuple type, from which one can build binary trees. There is an interpretation of Scheme values that allows one to treat these trees as lists. The same interpretation is applied to immutable pairs.
Because the empty list, written as ‘()’, is already immutable, it is shared between mutable and immutable lists as the termination marker. It is the only Scheme object that is both a mutable list and an immutable list.
Users should note that dotted lists, whether mutable or immutable, are not commonly used, and are considered by many Scheme programmers to be an ugly artifact of Scheme’s lack of a true list type. Dotted ilists are not fully supported by this SRFI. Most procedures are defined only on proper ilists that is, ‘()’–terminated ilists. The procedures that will also handle dotted ilists are specifically marked. While this design decision restricts the domain of possible arguments one can pass to these procedures, it has the benefit of allowing the procedures to catch the error cases where programmers inadvertently pass scalar values to an ilist procedure by accident, e.g., by switching the arguments to a procedure call.
Next: srfi ilists quotation, Previous: srfi ilists rationale, Up: srfi ilists [Index]