Pairs and Lists in The Racket Guide introduces pairs and lists.
A pair combines exactly two values. The first value is accessed with the car procedure, and the second value is accessed with the cdr procedure. Pairs are not mutable (but see Mutable Pairs and Lists).
A list is recursively defined: it is either the constant null, or it is a pair whose second value is a list.
A list can be used as a single-valued sequence (see Sequences). The elements of the list serve as elements of the sequence. See also in-list.
Cyclic data structures can be created using only immutable pairs via read or make-reader-graph. If starting with a pair and using some number of cdrs returns to the starting pair, then the pair is not a list.
See Reading Pairs and Lists for information on reading pairs and lists and Printing Pairs and Lists for information on printing pairs and lists.
4.10.1 Pair Constructors and Selectors๐โนReturns #t if v is a pair, #f otherwise.
Examples:
Returns #t if v is the empty list, #f otherwise.
Examples:
Returns a newly allocated pair whose first element is a and second element is d. When d is a list, the allocated pair is also a list.
Examples:
> (cons 1 2)'(1 . 2)
> (cons 1 '())'(1)
Returns the first element of the pair p.
Examples:
> (car '(1 2))1
> (car '(2 . 3))2
Returns the second element of the pair p.
Examples:
> (cdr '(1 2))'(2)
> (cdr '(2 . 3))3
The empty list.
Examples:
Returns #t if v is a list: either the empty list, or a pair whose second element is a list. This procedure effectively takes constant time due to internal caching (so that any necessary traversals of pairs can in principle count as an extra cost of allocating the pairs).
Examples:
Returns a newly allocated list containing the vs as its elements.
Examples:
Like
list, but the last argument is used as the tail of the result, instead of the final element. The result is a list only if the last argument is a list.
Examples:
Creates a list of
nelements by applying
procto the integers from
0to
(sub1 n)in order. If
lstis the resulting list, then
(list-ref lst i)is the value produced by
(proc i).
Examples:
4.10.2 List Operations๐โนReturns the number of elements in lst. This function takes time proportional to that length.
Examples:
Returns the element of
lstat position
pos, where the listโs first element is position
0. If the list has
posor fewer elements, then the
exn:fail:contractexception is raised.
The lst argument need not actually be a list; lst must merely start with a chain of at least (add1 pos) pairs.
This function takes time proportional to pos.
Examples:
Returns the list after the first
poselements of
lst. If the list has fewer than
poselements, then the
exn:fail:contractexception is raised.
The lst argument need not actually be a list; lst must merely start with a chain of at least pos pairs.
This function takes time proportional to pos.
Examples:
When given all list arguments, the result is a list that contains all of the elements of the given lists in order. The last argument is used directly in the tail of the result.
The last argument need not be a list, in which case the result is an โimproper list.โ
This function takes time proportional to the length of all arguments (added together) except the last argument.
Examples:
Returns a list that has the same elements as lst, but in reverse order.
This function takes time proportional to the length of lst.
Example:
4.10.3 List Iteration๐โนApplies proc to the elements of the lsts from the first elements to the last. The proc argument must accept the same number of arguments as the number of supplied lsts, and all lsts must have the same number of elements. The result is a list containing each result of proc in order.
Examples:
'(2 3 4 5)
> (map (lambda (number1 number2) (+ number1 number2)) '(1 2 3 4) '(10 100 1000 10000))'(11 102 1003 10004)
Similar to
mapin the sense that
procis applied to each element of
lst, but
The andmap function is actually closer to foldl than map, since andmap doesnโt produce a list. Still, (andmap f (list x y z)) is equivalent to (and (f x) (f y) (f z)) in the same way that (map f (list x y z)) is equivalent to (list (f x) (f y) (f z)).
the result is #f if any application of proc produces #f, in which case proc is not applied to later elements of the lsts; and
the result is that of proc applied to the last elements of the lsts; more specifically, the application of proc to the last elements in the lsts is in tail position with respect to the andmap call.
If the lsts are empty, then #t is returned.
Examples:
Similar to
mapin the sense that
procis applied to each element of
lst, but
To continue the andmap note above, (ormap f (list x y z)) is equivalent to (or (f x) (f y) (f z)).
the result is #f if every application of proc produces #f; and
the result is that of the first application of proc producing a value other than #f, in which case proc is not applied to later elements of the lsts; the application of proc to the last elements of the lsts is in tail position with respect to the ormap call.
If the lsts are empty, then #f is returned.
Examples:
Similar to
map, but
procis called only for its effect, and its result (which can be any number of values) is ignored.
Example:
Like
map,
foldlapplies a procedure to the elements of one or more lists. Whereas
mapcombines the return values into a list,
foldlcombines the return values in an arbitrary way that is determined by
proc.
If foldl is called with n lists, then proc must take n+1 arguments. The extra argument is the combined return values so far. The proc is initially invoked with the first item of each list, and the final argument is init. In subsequent invocations of proc, the last argument is the return value from the previous invocation of proc. The input lsts are traversed from left to right, and the result of the whole foldl application is the result of the last application of proc. If the lsts are empty, the result is init.
Unlike foldr, foldl processes the lsts in constant space (plus the space for each call to proc).
Examples:
> (foldl cons '() '(1 2 3 4))'(4 3 2 1)
> (foldl + 0 '(1 2 3 4))10
> (foldl (lambda (a b result) (* result (- a b))) 1 '(1 2 3) '(4 5 6))-27
Like
foldl, but the lists are traversed from right to left. Unlike
foldl,
foldrprocesses the
lsts in space proportional to the length of
lsts (plus the space for each call to
proc).
Examples:
4.10.4 More List Iteration๐โนThe bindings in this section are provided by the sequence-tools-lib package, which acts as an extension to the base sequence libraries.
Like
foldl, but produces a list containing all the results of applying
procas well as the initial accumulator.
Examples:
Examples:
4.10.5 List Filtering๐โนReturns a list with the elements of lst for which pred produces a true value. The pred procedure is applied to each element from first to last.
Example:
Returns a list that is like lst, omitting the first element of lst that is equal to v using the comparison procedure proc (which must accept two arguments), with v as the first argument and an element in lst as the second argument. If no element in lst is equal to v (according to proc), lst is returned unchanged.
Examples:
Changed in version 8.2.0.2 of package base: Guaranteed that the output is eq? to lst if no removal occurs.
Examples:
> (remq 2 (list 1 2 3 4 5))'(1 3 4 5)
> (remq '(2) (list '(1) '(2) '(3)))'((1) (2) (3))
> (remq "2" (list "1" "2" "3"))'("1" "3")
> (remq #\c (list #\a #\b #\c))'(#\a #\b)
Examples:
> (remv 2 (list 1 2 3 4 5))'(1 3 4 5)
> (remv '(2) (list '(1) '(2) '(3)))'((1) (2) (3))
> (remv "2" (list "1" "2" "3"))'("1" "3")
> (remv #\c (list #\a #\b #\c))'(#\a #\b)
Examples:
Added in version 8.5.0.3 of package base.
Like
remove, but removes from
lstevery instance of every element of
v-lst.
Example:
Changed in version 8.2.0.2 of package base: Guaranteed that the output is eq? to lst if no removal occurs.
Example:
Example:
Examples:
Added in version 8.5.0.3 of package base.
Returns a list sorted according to the less-than? procedure, which takes two elements of lst and returns a true value if the first is less (i.e., should be sorted earlier) than the second.
The sort is stable; if two elements of lst are โequalโ (i.e., less-than? does not return a true value when given the pair in either order), then the elements preserve their relative order from lst in the output list. To preserve this guarantee, use sort with a strict comparison functions (e.g., < or string<?; not <= or string<=?).
Because of the peculiar fact that the IEEE-754 number system specifies that +nan.0 is neither greater nor less than nor equal to any other number, sorting lists containing this value may produce a surprising result.
The #:key argument extract-key is used to extract a key value for comparison from each list element, where #f is replaced by (lambda (x) x) That is, the full comparison procedure is essentially
(lambda (x y) (less-than? (extract-key x) (extract-key y)))
By default, extract-key is applied to two list elements for every comparison, but if cache-keys? is true, then the extract-key function is used exactly once for each list item. Supply a true value for cache-keys? when extract-key is an expensive operation; for example, if file-or-directory-modify-seconds is used to extract a timestamp for every file in a list, then cache-keys? should be #t to minimize file-system calls, but if extract-key is car, then cache-keys? should be #f. As another example, providing extract-key as (lambda (x) (random)) and #t for cache-keys? effectively shuffles the list.
Examples:
> (sort '(1 3 4 2) <)4.10.6 List Searching๐โน'(1 2 3 4)
> (sort '("aardvark" "dingo" "cow" "bear") string<?)'("aardvark" "bear" "cow" "dingo")
'(("aardvark") ("bear") ("cow") ("dingo"))
Locates the first element of lst that is equal to v according to is-equal?. If such an element exists, the tail of lst starting with that element is returned. Otherwise, the result is #f.
The lst argument need not actually be a list; lst must merely start with a chain of pairs until a matching element is found. If no matching element is found, then lst must be a list (and not a cyclic list). The result can be a non-list in the case that an element is found and the returned tail of lst is a non-list.
Examples:
Examples:
Added in version 8.5.0.3 of package base.
Examples:
Like
member, but finds an element using
eq?.
Examples:
Like
member, but finds an element using the predicate
proc; an element is found when
procapplied to the element returns a true value.
Example:
Like
memf, but returns the element or
#finstead of a tail of
lstor
#f.
Notably, if #f is an element of lst, then the result of #f is ambiguous: it may indicate that no element satisfies proc, or may indicate that the element #f satisfies proc.
Example:
Locates the first element of
lstwhose
caris equal to
vaccording to
is-equal?. If such an element exists, the pair (i.e., an element of
lst) is returned. Otherwise, the result is
#f.
The lst argument need not actually be a list of pairs; lst must merely start with a chain of pairs contains pairs until a matching element is found. If no matching element is found, then lst must be a list of pairs (and not a cyclic list).
Examples:
Examples:
Added in version 8.5.0.3 of package base.
Like
assoc, but finds an element using
eqv?.
Example:
Like
assoc, but finds an element using
eq?.
Example:
Like
assoc, but finds an element using the predicate
proc; an element is found when
procapplied to the
carof an
lstelement returns a true value.
Example:
4.10.7 Pair Accessor Shorthands๐โนExample:
> (cdar '((7 6 5 4 3 2 1) 8 9))'(6 5 4 3 2 1)
Example:
> (caaar '(((6 5 4 3 2 1) 7) 8 9))6
Example:
> (caadr '(9 (7 6 5 4 3 2 1) 8))7
Example:
> (cadar '((7 6 5 4 3 2 1) 8 9))6
Example:
> (cdaar '(((6 5 4 3 2 1) 7) 8 9))'(5 4 3 2 1)
Example:
> (cdadr '(9 (7 6 5 4 3 2 1) 8))'(6 5 4 3 2 1)
Example:
> (cddar '((7 6 5 4 3 2 1) 8 9))'(5 4 3 2 1)
Example:
> (caaaar '((((5 4 3 2 1) 6) 7) 8 9))5
Example:
> (caaadr '(9 ((6 5 4 3 2 1) 7) 8))6
Example:
> (caadar '((7 (5 4 3 2 1) 6) 8 9))5
Example:
> (caaddr '(9 8 (6 5 4 3 2 1) 7))6
Example:
> (cadaar '(((6 5 4 3 2 1) 7) 8 9))5
Example:
> (cadadr '(9 (7 6 5 4 3 2 1) 8))6
Example:
> (caddar '((7 6 5 4 3 2 1) 8 9))5
Example:
> (cdaaar '((((5 4 3 2 1) 6) 7) 8 9))'(4 3 2 1)
Example:
> (cdaadr '(9 ((6 5 4 3 2 1) 7) 8))'(5 4 3 2 1)
Example:
> (cdadar '((7 (5 4 3 2 1) 6) 8 9))'(4 3 2 1)
Example:
> (cdaddr '(9 8 (6 5 4 3 2 1) 7))'(5 4 3 2 1)
Example:
> (cddaar '(((6 5 4 3 2 1) 7) 8 9))'(4 3 2 1)
Example:
> (cddadr '(9 (7 6 5 4 3 2 1) 8))'(5 4 3 2 1)
Example:
> (cdddar '((7 6 5 4 3 2 1) 8 9))4.10.8 Additional List Functions and Synonyms๐โน'(4 3 2 1)
The empty list.
Examples:
Example:
Examples:
The same as
(car lst), but only for lists (that are not empty).
Example:
> (first '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))1
The same as
(cdr lst), but only for lists (that are not empty).
Example:
> (rest '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))'(2 3 4 5 6 7 8 9 10 11 12 13 14 15)
Returns the second element of the list.
Example:
> (second '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))2
Returns the third element of the list.
Example:
> (third '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))3
Returns the fourth element of the list.
Example:
> (fourth '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))4
Returns the fifth element of the list.
Example:
> (fifth '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))5
Returns the sixth element of the list.
Example:
> (sixth '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))6
Returns the seventh element of the list.
Example:
> (seventh '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))7
Returns the eighth element of the list.
Example:
> (eighth '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))8
Returns the ninth element of the list.
Example:
> (ninth '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))9
Returns the tenth element of the list.
Example:
> (tenth '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))10
Returns the eleventh element of the list.
Example:
> (eleventh '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))11
Added in version 8.15.0.3 of package base.
Returns the twelfth element of the list.
Example:
> (twelfth '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))12
Added in version 8.15.0.3 of package base.
Returns the thirteenth element of the list.
Example:
> (thirteenth '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))13
Added in version 8.15.0.3 of package base.
Returns the fourteenth element of the list.
Example:
> (fourteenth '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))14
Added in version 8.15.0.3 of package base.
Returns the fifteenth element of the list.
Example:
> (fifteenth '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))15
Added in version 8.15.0.3 of package base.
Returns the last element of the list.
This function takes time proportional to the length of lst.
Example:
> (last '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))15
Returns the last pair of a (possibly improper) list.
This function takes time proportional to the โlengthโ of p.
Example:
Returns a newly constructed list of length k, holding v in all positions.
Example:
> (make-list 7 'foo)'(foo foo foo foo foo foo foo)
Returns a list that is the same as
lstexcept at the specified index. The element at the specified index is
(updater (list-ref lst pos)).
This function takes time proportional to pos.
Added in version 6.3 of package base.
Returns a list that is the same as lst except at the specified index. The element at the specified index is value.
This function takes time proportional to pos.
Example:
> (list-set '(zero one two) 2 "two")'(zero one "two")
Added in version 6.3 of package base.
Like
member, but returns the index of the first element found instead of the tail of the list.
Example:
Added in version 6.7.0.3 of package base.
Like
index-ofbut with the predicate-searching behavior of
memf.
Example:
Added in version 6.7.0.3 of package base.
Like
index-of, but returns the a list of all the indexes where the element occurs in the list instead of just the first one.
Example:
Added in version 6.7.0.3 of package base.
Example:
Added in version 6.7.0.3 of package base.
Returns a fresh list whose elements are the first
poselements of
lst. If
lsthas fewer than
poselements, the
exn:fail:contractexception is raised.
The lst argument need not actually be a list; lst must merely start with a chain of at least pos pairs.
This function takes time proportional to pos.
Examples:
> (take '(1 2 3 4 5) 2)'(1 2)
> (take 'non-list 0)'()
Returns the same result as
except that it can be faster, but it will still take time proportional to pos.
Returns a fresh list whose elements are taken successively from lst as long as they satisfy pred. The returned list includes up to, but not including, the first element in lst for which pred returns #f.
The lst argument need not actually be a list; the chain of pairs in lst will be traversed until a non-pair is encountered.
Examples:
Drops elements from the front of lst as long as they satisfy pred.
Examples:
Returns the same result as
except that it can be faster.
Returns the
listโs
pos-length tail. If
lsthas fewer than
poselements, then the
exn:fail:contractexception is raised.
The lst argument need not actually be a list; lst must merely end with a chain of at least pos pairs.
This function takes time proportional to the length of lst.
Examples:
Returns a fresh list whose elements are the prefix of
lst, dropping its
pos-length tail. If
lsthas fewer than
poselements, then the
exn:fail:contractexception is raised.
The lst argument need not actually be a list; lst must merely end with a chain of at least pos pairs.
This function takes time proportional to the length of lst.
Examples:
Returns the same result as
(values (drop-right lst pos) (take-right lst pos))
except that it can be faster, but it will still take time proportional to the length of lst.
Examples:
True if l is a prefix of r.
Added in version 6.3 of package base.
Returns the longest common prefix of l and r.
Added in version 6.3 of package base.
Returns the tails of l and r with the common prefix removed.
Added in version 6.3 of package base.
Returns the longest common prefix together with the tails of l and r with the common prefix removed.
Added in version 6.3 of package base.
(add-between lst v [ #:before-first before-first #:before-last before-last #:after-last after-last #:splice? splice?]) โ list?lst : list? v : any/c before-first : list? = '() before-last : any/c = v after-last : list? = '() splice? : any/c = #f
Returns a list with the same elements as lst, but with v between each pair of elements in lst; the last pair of elements will have before-last between them, instead of v (but before-last defaults to v).
If splice? is true, then v and before-last should be lists, and the list elements are spliced into the result. In addition, when splice? is true, before-first and after-last are inserted before the first element and after the last element respectively.
Examples:
> (add-between '(x y z) 'and)'(x and y and z)
> (add-between '(x) 'and)'(x)
> (add-between '("a" "b" "c" "d") "," #:before-last "and")'("a" "," "b" "," "c" "and" "d")
> (add-between '(x y z) '(-) #:before-last '(- -) #:before-first '(begin) #:after-last '(end LF) #:splice? #t)'(begin x - y - - z end LF)
Examples:
> (append* '(a) '(b) '((c) (d)))'(a b c d)
'("Alpha" ", " "Beta" ", " "Gamma")
Flattens an arbitrary S-expression structure of pairs into a list. More precisely,
vis treated as a binary tree where pairs are interior nodes, and the resulting list contains all of the non-
nullleaves of the tree in the same order as an inorder traversal.
Examples:
Returns the first duplicate item in lst. More precisely, it returns the first x such that there was a previous y where (same? (extract-key x) (extract-key y)).
If no duplicate is found, then failure-result determines the result:
If failure-result is a procedure, it is called (through a tail call) with no arguments to produce the result.
Otherwise, failure-result is returned as the result.
The same? argument should be an equivalence predicate such as equal? or eqv?. The procedures equal?, eqv?, eq?, and equal-always? automatically use a dictionary for speed.
Examples:
Added in version 6.3 of package base.
Changed in version 6.11.0.2: Added the #:default optional argument.
Returns a list that has all items in lst, but without duplicate items, where same? determines whether two elements of the list are equivalent. The resulting list is in the same order as lst, and for any item that occurs multiple times, the first one is kept.
The #:key argument extract-key is used to extract a key value from each list element, so two items are considered equal if (same? (extract-key x) (extract-key y)) is true.
Like check-duplicates, if the same? argument is one of equal?, eqv?, eq?, and equal-always?, the operation can be specialized to improve performance.
Examples:
Like
(map proc lst ...), except that, if
procreturns
#false, that element is omitted from the resulting list. In other words,
filter-mapis equivalent to
(filter (lambda (x) x) (map proc lst ...)), but more efficient, because
filter-mapavoids building the intermediate list.
Example:
Example:
Similar to
filter, except that two values are returned: the items for which
predreturns a true value, and the items for which
predreturns
#f.
The result is the same as
but pred is applied to each item in lst only once.
Example:
Similar to
in-range, but returns lists.
The resulting list holds numbers starting at start and whose successive elements are computed by adding step to their predecessor until end (excluded) is reached. If no starting point is provided, 0 is used. If no step argument is provided, 1 is used.
Like in-range, a range application can provide better performance when it appears directly in a for clause.
Examples:
> (range 10)'(0 1 2 3 4 5 6 7 8 9)
> (range 10 20)'(10 11 12 13 14 15 16 17 18 19)
> (range 20 40 2)'(20 22 24 26 28 30 32 34 36 38)
> (range 20 10 -1)'(20 19 18 17 16 15 14 13 12 11)
> (range 10 15 1.5)'(10 11.5 13.0 14.5)
Changed in version 6.7.0.4 of package base: Adjusted to cooperate with for in the same way that in-range does.
The resulting list holds numbers starting at start and whose successive elements are computed by adding step to their predecessor until end (included) is reached. If no step argument is provided, 1 is used.
Like in-inclusive-range, an inclusive-range application can provide better performance when it appears directly in a for clause.
Examples:
Added in version 8.0.0.13 of package base.
Example:
Like
filter, but the meaning of the
predpredicate is reversed: the result is a list of all items for which
predreturns
#f.
Example:
Returns a list with all elements from lst, randomly shuffled.
Examples:
> (shuffle '(1 2 3 4 5 6))'(3 2 1 4 5 6)
> (shuffle '(1 2 3 4 5 6))'(5 4 6 2 3 1)
> (shuffle '(1 2 3 4 5 6))'(6 4 2 3 1 5)
Return a list of all combinations of elements in the input list (a.k.a. the
powerset of
lst). If
sizeis given, limit results to combinations of
sizeelements.
Examples:
Returns a sequence of all combinations of elements in the input list, or all combinations of length
sizeif
sizeis given. Builds combinations one-by-one instead of all at once.
Examples:
Returns a list of all permutations of the input list. Note that this function works without inspecting the elements, and therefore it ignores repeated elements (which will result in repeated permutations). Raises an error if the input list contains more than 256 elements.
Examples:
Returns a sequence of all permutations of the input list. It is equivalent to
(in-list (permutations l))but much faster since it builds the permutations one-by-one on each iteration. Raises an error if the input list contains more than 256 elements.
Returns the first element in the list
lstthat minimizes the result of
proc. Signals an error on an empty list. See also
min.
Examples:
> (argmin car '((3 pears) (1 banana) (2 apples)))'(1 banana)
> (argmin car '((1 banana) (1 orange)))'(1 banana)
Returns the first element in the list
lstthat maximizes the result of
proc. Signals an error on an empty list. See also
max.
Examples:
> (argmax car '((3 pears) (1 banana) (2 apples)))'(3 pears)
> (argmax car '((3 pears) (3 oranges)))'(3 pears)
Groups the given list into equivalence classes, with equivalence being determined by
same?. Within each equivalence class,
group-bypreserves the ordering of the original list. Equivalence classes themselves are in order of first appearance in the input.
Example:
> (group-by (lambda (x) (modulo x 3)) '(1 2 1 2 54 2 5 43 7 2 643 1 2 0))'((1 1 43 7 643 1) (2 2 2 5 2 2) (54 0))
Added in version 6.3 of package base.
Computes the n-ary cartesian product of the given lists.
Examples:
> (cartesian-product '(1 2 3) '(a b c))'((1 a) (1 b) (1 c) (2 a) (2 b) (2 c) (3 a) (3 b) (3 c))
> (cartesian-product '(4 5 6) '(d e f) '(#t #f))'((4 d #t)
(4 d #f)
(4 e #t)
(4 e #f)
(4 f #t)
(4 f #f)
(5 d #t)
(5 d #f)
(5 e #t)
(5 e #f)
(5 f #t)
(5 f #f)
(6 d #t)
(6 d #f)
(6 e #t)
(6 e #f)
(6 f #t)
(6 f #f))
Added in version 6.3 of package base.
Returns a list that is like lst, omitting the first element of lst for which pred produces a true value.
Added in version 6.3 of package base.
Like
remf, but removes all the elements for which
predproduces a true value.
Added in version 6.3 of package base.
4.10.9 More List Grouping๐โนThe bindings in this section are provided by the sequence-tools-lib package, which acts as an extension to the base sequence libraries.
Returns a list of sliding windows such that each window contains size elements with the window sliding step positions on each iteration. If the number of remaining elements is less than size, then those elements are dropped.
Examples:
> (windows 3 1 '(1 2 3 4))'((1 2 3) (2 3 4))
> (windows 2 3 '(1 2 3))'((1 2))
> (windows 1 2 '(1 2 3 4))'((1) (3))
Returns a list such that each element is a sublist (slice) that is constructed from comparing each pair of adjacent elements. All pairs of elements that satisfy proc will be grouped together into a slice, otherwise the element will start a new slice.
Examples:
4.10.10 Immutable Cyclic Data๐โนReturns a value like
v, with
placeholderscreated by
make-placeholderreplaced with the values that they contain, and with
hash placeholderscreated by
make-hash-placeholderwith an immutable hash table. No part of
vis mutated; instead, parts of
vare copied as necessary to construct the resulting graph, where at most one copy is created for any given value.
Since the copied values can be immutable, and since the copy is also immutable, make-reader-graph can create cycles involving only immutable pairs, vectors, boxes, and hash tables.
Only the following kinds of values are copied and traversed to detect placeholders:
pairs
vectors, both mutable and immutable
boxes, both mutable and immutable
hash tables, both mutable and immutable
instances of a prefab structure type
placeholders created by make-placeholder and make-hash-placeholder
Due to these restrictions, make-reader-graph creates exactly the same sort of cyclic values as read.
Example:
Changes the value of ph to v.
Returns the value of ph.
Added in version 8.5.0.3 of package base.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4