3.6 Lists
Returns a list containing the given values.
procedure
(join a b) → pair?
a : any b : any
Joins a and b into a pair. If b is Null, a
list is created containing a. If b is a list, a is
joined to the head of the list.
Returns the head (first element) of the list l.
Returns the remainder of list l after the head. If the list has only
one element, returns Null.
Generates a list of numbers, incrementing from start to finish
by n. If no n is provided, defaults to 1. Note that, unlike
BASIC’s for x = y to z, descending sequences where start is
greater than finish can only be declared by including a negative n.
Otherwise only Null will be returned.
Given a single-argument function fun, returns a list with fun
applied to each item in l.
Given a predicate fun, returns a new list containing only those
elements of l for which fun returns True.
Returns the number of items in l.
Given a function fun with two arguments, returns the cumulative result
of fun being applied to consecutive pairs, starting from base
and the rightmost element of l.
Similar to foldr, except that it combines pairs from the left, starting
with the head of l and base.
Returns a list with the order of l reversed.
Returns the nth entry of l, indexed from 1.
Walks through nested lists according to the given dims, essentially
finding index recursively for an arbitrary number of dimensions. For example,
given a nested list three lists deep, (index* l 2 3 1) would return the
1st element of the third element of the 2nd lst, like so:
Examples:
> (def dave '(1 (2 3 (4 5)) 6)) > (dave 2 3 1) 4
Returns a list of the leftmost n elements of l.
Returns a list of the rightmost n elements of l.
Returns n entries of l starting from index idx.
Returns a slice of l, starting at first and ending at
last. If last is not provided, it defaults to the end of the
list.
Returns a list with l2 appended to the end of l1.
Returns a list of the given ls appended together in order.
Searches the heads of a list of lists l and returns the first matching
list or False.
Searches the heads of a list of lists l, and if it finds tgt,
returns a new list with the tail of tgt substituted for a new list containing new. Otherwise,
returns False.
Searches the heads of a list of lists l, and if it finds tgt,
returns a new list with the tail of tgt substituted for new. Otherwise,
returns False. For clarity’s sake, the following examples may be more illustrative of the
difference between subst and subst*.
Examples:
> (def alst '((foo 1) (bar 2))) > (subst 'foo 3 alst) '((foo 3) (bar 2))
> (subst 'foo '(3) alst) '((foo (3)) (bar 2))
> (subst* 'foo 3 alst) '((foo . 3) (bar 2))
> (subst* 'foo '(3) alst) '((foo 3) (bar 2))
Returns a list of the heads of a list of lists.
Sorts list l according to the comparison function fun.
Returns a new list of lists combining l1 and l2. Excess length
of either list is dropped.
Returns a new list, combining the matching pairs of each list with fun.
Excess length of either list is dropped.
Traverses a list, and flattens any nested lists into a single one-dimensional list.