Predeclared in LINKED LISTS

Functions

append(xs, ys) → {linked_list}

Returns a linked list that results from appending the linked list ys to the linked list xs.
Parameters:
Name Type Description
xs linked_list given linked list
ys linked_list given linked list
Returns:
linked list that results from appending ys to xs
Type
linked_list

build_llist(fun, n) → {linked_list}

Makes a linked list with n elements by applying the unary function fun to the numbers 0 to n - 1.
Parameters:
Name Type Description
fun function given unary function
n int number of elements in the linked list
Returns:
linked list with n elements generated by applying fun to 0 to n - 1
Type
linked_list

draw_data(value1,)

PRIMITIVE Visualizes the arguments in a separate drawing area in the Source Academy using box-and-pointer diagrams.
Parameters:
Name Type Description
value1, value value2, ...values - given values

enum_llist(start, end) → {linked_list}

Makes a linked list with elements from start to end (inclusive).
Parameters:
Name Type Description
start int starting element of the linked list
end int ending element of the linked list
Returns:
linked list with elements from start to end (inclusive)
Type
linked_list

filter(pred, xs) → {linked_list}

Returns a linked list that contains only those elements for which the one-argument function pred returns True.
Parameters:
Name Type Description
pred function given one-argument function
xs linked_list given linked list
Returns:
linked list that contains only those elements of xs for which pred returns True
Type
linked_list

for_each(fun, xs)

Applies the unary function fun to every element of the linked list xs.
Parameters:
Name Type Description
fun function given unary function
xs linked_list given linked list
PRIMITIVE Returns head (first component) of given pair p.
Parameters:
Name Type Description
p pair given pair
Returns:
head of p
Type
value

is_llist(xs) → {boolean}

PRIMITIVE Returns True if xs is a linked list as defined in the textbook, and False otherwise.
Parameters:
Name Type Description
xs value given value
Returns:
whether xs is a linked list
Type
boolean

is_none(x) → {boolean}

PRIMITIVE Returns True if x is the empty linked list None, and False otherwise.
Parameters:
Name Type Description
x value given value
Returns:
whether x is None
Type
boolean

is_pair(x) → {boolean}

PRIMITIVE Returns True if x is a pair and False otherwise.
Parameters:
Name Type Description
x value given value
Returns:
whether x is a pair
Type
boolean

length(xs) → {int}

Returns the length of the linked list xs.
Parameters:
Name Type Description
xs linked_list given linked list
Returns:
length of xs
Type
int

llist(value1,) → {linked_list}

PRIMITIVE Given n values, returns a linked list of length n. The elements of the linked list are the given values in the given order.
Parameters:
Name Type Description
value1, value value2, ...values - given values
Returns:
linked list containing all values
Type
linked_list

llist_ref(xs, n) → {value}

Returns the element of linked list xs at position n (0-indexed).
Parameters:
Name Type Description
xs linked_list given linked list
n int index of the element to return
Returns:
element of xs at position n
Type
value

llist_to_string(xs) → {string}

Returns a string that represents linked list xs using the text-based box-and-pointer notation.
Parameters:
Name Type Description
xs linked_list given linked list
Returns:
string that represents xs using box-and-pointer notation
Type
string

map(f, xs) → {linked_list}

Returns a linked list that results from linked list xs by element-wise application of unary function f.
Parameters:
Name Type Description
f function given unary function
xs linked_list given linked list
Returns:
linked list that results from element-wise application of f to xs
Type
linked_list

member(v, xs) → {linked_list}

Returns first postfix sub-linked list whose head is identical to v (using ==). Returns None if the element does not occur in the linked list.
Parameters:
Name Type Description
v value given value
xs linked_list given linked list
Returns:
first postfix sub-linked list of xs whose head is identical to v, or None if no such sub-linked list exists
Type
linked_list

pair(x, y) → {pair}

PRIMITIVE Makes a pair whose head (first component) is x and whose tail (second component) is y.
Parameters:
Name Type Description
x value given head
y value given tail
Returns:
pair with x as head and y as tail
Type
pair

reduce(f, initial, xs) → {value}

Applies binary function f to the elements of xs from right-to-left order.
Parameters:
Name Type Description
f function given binary function
initial value initial value for the accumulation
xs linked_list given linked list
Returns:
result of applying f to the elements of xs from right-to-left order, starting with initial
Type
value

remove(v, xs) → {linked_list}

Returns a linked list that results from xs by removing the first item from xs that is identical (==) to v.
Parameters:
Name Type Description
v value given value
xs linked_list given linked list
Returns:
linked list that results from removing the first item from xs that is identical to v
Type
linked_list

remove_all(v, xs) → {linked_list}

Returns a linked list that results from xs by removing all items from xs that are identical (==) to v.
Parameters:
Name Type Description
v value given value
xs linked_list given linked list
Returns:
linked list that results from removing all items from xs that are identical to v
Type
linked_list

reverse(xs) → {linked_list}

Returns linked list xs in reverse order.
Parameters:
Name Type Description
xs linked_list given linked list
Returns:
linked list xs in reverse order
Type
linked_list

tail(p) → {value}

PRIMITIVE Returns tail (second component) of given pair p.
Parameters:
Name Type Description
p pair given pair
Returns:
tail of p
Type
value