20static bool cons_delete_p(
struct cons **list,
struct cons *cell,
void *user);
22static bool cons_remove_p(
struct cons **list,
struct cons *cell,
void *user);
31 (void)
cons(list, cell);
37 if (pred(list, cell, user)) {
57static bool cons_find_p(
struct cons **list,
struct cons *cell,
void *user) {
63 return cons_loop(list, cons_find_p, cell);
66static bool cons_delete_p(
struct cons **list,
struct cons *cell,
void *user) {
76 struct cons *deleted = *found;
86 struct cons *removed = *found;
161 struct cons *cell = (
struct cons *)malloc(
sizeof(
struct cons));
A simple implementation of cons cells for building linked lists.
static struct cons * cons_cdr(const struct cons *cell)
Accessor for the cdr field of a cons cell.
#define CONS_NIL_P(_cell)
Returns true if the cons cell is CONS_NIL.
#define CONS_NIL
The empty list (a NULL pointer).
static void cons_rplacd(struct cons *cell, struct cons *cdr)
Mutator for the cdr field of a cons cell.
static void * cons_car(const struct cons *cell)
Accessor for the car field of a cons cell.
#define CONS_NOT_NIL_P(_cell)
Returns true if the cons cell is not CONS_NIL.
static void cons_init(struct cons *cell, void *car)
Initialises a cons cell with the given car value and cdr set to CONS_NIL.
struct cons * cons_delete(struct cons **list, void *car)
Destructively deletes the first cons cell with the specified car value from the list.
void cons_free(struct cons *cell)
Frees a heap-allocated cons cell.
size_t cons_length(const struct cons *cell)
Computes the length of a linked list of cons cells.
void cons_reverse(struct cons **list)
Reverses a linked list of cons cells in place.
struct cons ** cons_find(struct cons **list, void *cell)
Finds the first cons cell in a list that matches a given identity.
struct cons * cons_append(struct cons *cell1, struct cons *cell2)
Appends one list of cons cells to another.
struct cons * cons_member(struct cons *cell, void *car)
Returns the first cons cell in a linked list of cons cells whose car field matches the specified valu...
struct cons ** cons_loop(struct cons **list, bool(*pred)(struct cons **list, struct cons *cell, void *user), void *user)
Loops through a list of cons cells, applying a predicate function to each cell.
struct cons * cons_last(struct cons *cell)
Returns the last cons cell in a linked list of cons cells.
struct cons * cons_remove(struct cons **list, struct cons *cell)
Destructively removes the specified cons cell from the list.
struct cons * cons_heap(void *car)
Allocates a new cons cell on the heap.
struct cons ** cons_prepend(struct cons **list, struct cons *cell)
Prepends a cons cell to a list, returning the updated list pointer.
struct cons * cons_nth(struct cons *cell, size_t nth)
Returns the n'th cons cell in a linked list of cons cells.
Construct cell structure for building linked lists.
struct cons * cdr
Contents of Decrement Register (CDR).
void * car
Contents of Address Register (CAR).