srfi-1- List library
SRFI-1 is a rich collection of list manipulation library
It is available by saying
The implementation is based on Olin Shivers’s reference implementation.
Note that Gauche supports quite a few SRFI-1 procedures as built-in.
The following SRFI-1 procedures can be used
srfi-1 module. For the manual entries of
these procedures, Pairs and Lists.
null-list? cons* last member take drop take-right drop-right take! drop-right! delete delete! delete-duplicates delete-duplicates! assoc alist-copy alist-delete alist-delete! any every filter filter! fold fold-right find find-tail split-at split-at! iota
|• SRFI-1 List utilities:|
|• SRFI-1 Set operations:|
[SRFI-1] Equivalent to
(cons ca cd). Useful to pass to
[SRFI-1] Constructs an n-element list, in which
each element is generated by
(list-tabulate 4 values) ⇒ (0 1 2 3)
[SRFI-1] Constructs a circular list of the elements.
(circular-list 'z 'q) ⇒ (z q z q z q …)
(lambda (x) (not (pair? x))).
SRFI-1 says: Provided as a procedure as it can be useful as the termination condition for list-processing procedures that wish to handle all finite lists, both proper and dotted.
[SRFI-1] Determines list equality by comparing every n-th element of given lists by the procedure elt=.
It is an error to apply
list= to anything except proper lists.
The equality procedure must be consistent with
(eq? x y) ⇒ (elt= x y).
[SRFI-1] Returns n-th element of the (maybe improper) list.
[SRFI-1] Returns two values,
(car pair) and
(map list clist1 clist2 …).
zip is passed n lists, it returns a list as long as
the shortest of these lists, each element of which is an n-element list
comprised of the corresponding elements from the parameter lists.
(zip '(one two three) '(1 2 3) '(odd even odd even odd even odd even)) ⇒ ((one 1 odd) (two 2 even) (three 3 odd)) (zip '(1 2 3)) ⇒ ((1) (2) (3))
At least one of the argument lists must be finite:
(zip '(3 1 4 1) (circular-list #f #t)) ⇒ ((3 #f) (1 #t) (4 #f) (1 #t))
unzip1 takes a list of lists, where every list must
contain at least one element, and returns a list containing the
initial element of each such list.
unzip2 takes a list of lists, where every list
must contain at least two elements, and returns two values:
a list of the first elements, and a list of the second
unzip3 does the same for the first
three elements of the lists, and so on.
(unzip2 '((1 one) (2 two) (3 three))) ⇒ (1 2 3) and (one two three)
fold-right, but the procedure kons
cdr of the given clists, instead of
(pair-fold cons '() '(a b c d e)) ⇒ ((e) (d e) (c d e) (b c d e) (a b c d e)) (pair-fold-right cons '() '(a b c d e)) ⇒ ((a b c d e) (b c d e) (c d e) (d e) (e))
[SRFI-1] Fundamental recursive list constructor. Defined by the following recursion.
(unfold p f g seed tail-gen) ≡ (if (p seed) (tail-gen seed) (cons (f seed) (unfold p f g (g seed))))
That is, p determines where to stop, g is used to generate successive seed value from the current seed value, and f is used to map each seed value to a list element.
(unfold (pa$ = 53) integer->char (pa$ + 1) 48) ⇒ (#\0 #\1 #\2 #\3 #\4)
[SRFI-1] Fundamental iterative list constructor. Defined by the following recursion.
(unfold-right p f g seed tail) ≡ (let lp ((seed seed) (lis tail)) (if (p seed) lis (lp (g seed) (cons (f seed) lis))))
(unfold-right (pa$ = 53) integer->char (pa$ + 1) 48) ⇒ (#\4 #\3 #\2 #\1 #\0)
[SRFI-1] The procedure f is applied to each element of clist1 and corresponding elements of clist2s, and the result is collected to a list. Cells in clist1 is reused to construct the result list.
[SRFI-1] A variant of
map, but it guarantees to apply f
on each elements of arguments in a left-to-right order.
map implementation follows the same order,
this function is just a synonym of
for-each, but the procedure f is applied on
clists themselves first, then each
cdrs of them, and so on.
(pair-for-each write '(a b c)) ⇒ prints (a b c)(b c)(c)
remove simultaneously, i.e.
returns two lists, the first is the result of filtering elements of
list by pred, and the second is the result of
removing elements of list by pred.
(partition odd? '(3 1 4 5 9 2 6)) ⇒ (3 1 5 9) (4 2 6)
partition! is the linear-update variant. It may destructively
modifies list to produce the result.
[SRFI-1] Returns the longest initial prefix of clist whose elements all satisfy pred.
[SRFI-1] Drops the longest initial prefix of clist whose elements all satisfy pred, and returns the rest.
span is equivalent to
(values (take-while pred clist) (drop-while pred clist)).
break inverts the sense of pred.
Returns the index of the leftmost element that satisfies pred.
If no element satisfies pred,
#f is returned.
(cons (cons key datum) alist).
This is an alias of the Gauche builtin procedure
These procedures use a list as a set, that is, the elements in a list matter, but their order doesn’t.
All procedures in this category takes a comparison procedure elt=, as the first argument, which is used to determine two elements in the given sets are the same.
Since lists require linear time to search, those procedures aren’t suitable to deal with large sets. See Sets and bags, if you know your sets will contain more than a dozen items or so.
See also Combination library, which concerns combinations of elements in the set.
#t iff all elements in list1 are also included
in list2, and so on.
If no lists are given, or a single list is given,
#t is returned.
#t if all elements in list1 are in list2,
and all elements in list2 are in list1, and so on.
(lset= eq? '(b e a) '(a e b) '(e e b a)) ⇒ #t
[SRFI-1] Adds elt … to the set list, if each one is not already a member of list. (The order doesn’t matter).
(lset-adjoin eq? '(a b c) 'a 'e) ⇒ '(e a b c)
[SRFI-1] Returns the union of the sets list1 ….
[SRFI-1] Returns a set of elements that are in every lists.
[SRFI-1] Returns a set of elements that are in list1 but not in list2. In n-ary case, binary differece operation is simply folded.
[SRFI-1] Returns the exclusive-or of given sets; that is, the returned set consists of the elements that are in either list1 or list2, but not in both. In n-ary case, binary xor operation is simply folded.
[SRFI-1] Returns two sets, a difference and an intersection of given sets.
[SRFI-1] Linear update variant of the corresponding procedures. The cells in the first list argument may be reused to construct the result.