mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15:05 +02:00
WIP
This commit is contained in:
parent
999fc7186b
commit
045e871f7b
1 changed files with 90 additions and 0 deletions
|
@ -462,30 +462,120 @@ If x is circular, take! may return a shorter-than-expected list:
|
|||
|
||||
# length+
|
||||
|
||||
(length+ clist)
|
||||
|
||||
`length+` returns the length of the argument, or `#f` when applied to a circular list.
|
||||
|
||||
The length of a proper list is a non-negative integer `n` such that `cdr` applied `n` times to the list produces the empty list.
|
||||
|
||||
# zip
|
||||
|
||||
(zip clist1 clist2 ...)
|
||||
|
||||
This is equivalent to
|
||||
|
||||
(lambda lists (apply map list lists))
|
||||
|
||||
If 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
|
||||
|
||||
(unzip1 list)
|
||||
|
||||
`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. That is, it returns `(map car lists)`.
|
||||
|
||||
# unzip2
|
||||
|
||||
(unzip2 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 elements.
|
||||
|
||||
(unzip2 '((1 one) (2 two) (3 three))) =>
|
||||
(1 2 3)
|
||||
(one two three)
|
||||
|
||||
# unzip3
|
||||
|
||||
(unzip3 list)
|
||||
|
||||
`unzip3` does the same as `unzip2` for the first three elements of the lists.
|
||||
|
||||
# unzip4
|
||||
|
||||
(unzip4 list)
|
||||
|
||||
`unzip4` does the same as `unzip2` for the first four elements of the lists.
|
||||
|
||||
# unzip5
|
||||
|
||||
(unzip5 list)
|
||||
|
||||
`unzip5` does the same as `unzip2` for the first five elements of the lists.
|
||||
|
||||
# count
|
||||
|
||||
(count pred clist1 clist2)
|
||||
|
||||
`pred` is a procedure taking as many arguments as there are lists and returning a single value. It is applied element-wise to the elements of the lists, and a count is tallied of the number of elements that produce a true value. This count is returned. count is "iterative" in that it is guaranteed to apply pred to the list elements in a left-to-right order. The counting stops when the shortest list expires.
|
||||
|
||||
(count even? '(3 1 4 1 5 9 2 5 6)) => 3
|
||||
(count < '(1 2 4 8) '(2 4 6 8 10 12 14 16)) => 3
|
||||
|
||||
At least one of the argument lists must be finite:
|
||||
|
||||
(count < '(3 1 4 1) (circular-list 1 10)) => 2
|
||||
|
||||
# append!
|
||||
|
||||
(append! list1 ...)
|
||||
|
||||
`append!` is the "linear-update" variant of `append` -- it is allowed, but not required, to alter cons cells in the argument lists to construct the result list. The last argument is never altered; the result list shares structure with this parameter.
|
||||
|
||||
# append-reverse
|
||||
|
||||
(append-reverse rev-head tail)
|
||||
|
||||
`append-reverse` returns `(append (reverse rev-head) tail)`. It is provided because it is a common operation -- a common list-processing style calls for this exact operation to transfer values accumulated in reverse order onto the front of another list, and because the implementation is significantly more efficient than the simple composition it replaces. (But note that this pattern of iterative computation followed by a reverse can frequently be rewritten as a recursion, dispensing with the reverse and append-reverse steps, and shifting temporary, intermediate storage from the heap to the stack, which is typically a win for reasons of cache locality and eager storage reclamation.)
|
||||
|
||||
|
||||
# append-reverse!
|
||||
|
||||
(append-reverse! rev-head tail)
|
||||
|
||||
append-reverse! is just the linear-update variant -- it is allowed, but not required, to alter rev-head's cons cells to construct the result.
|
||||
|
||||
# concatenate
|
||||
|
||||
(concatenate list-of-lists)
|
||||
|
||||
This function appends the elements of its argument together. That is, concatenate returns
|
||||
|
||||
(apply append list-of-lists)
|
||||
|
||||
or, equivalently,
|
||||
|
||||
(reduce-right append '() list-of-lists)
|
||||
|
||||
The last element of the input list may be any value at all.
|
||||
|
||||
# concatenate!
|
||||
|
||||
(concatenate! list-of-lists)
|
||||
|
||||
`concatenate!` is the linear-update variant of `concatenate`.
|
||||
|
||||
# unfold
|
||||
|
||||
# fold
|
||||
|
|
Loading…
Add table
Reference in a new issue