|
cons
|
Defines the structure and functions for cons nodes. More...
#include "cons.h"

Go to the source code of this file.
Data Structures | |
| struct | cons_node |
| Structure representing a cons node. More... | |
Macros | |
| #define | CONS_NODE(_cell_, _head_) ((struct cons_node){.cell = (_cell_), .head = (_head_)}) |
| Constructs a cons node with the given cell and head. | |
| #define | CONS_NODE_NULL CONS_NODE(CONS(NULL, CONS_NIL), CONS_NIL) |
| A null cons node with no parent and no children. | |
Functions | |
| struct cons_node * | cons_car_node (struct cons_node *node) |
| Accessor for the parent node (super-node) of a cons node. | |
| struct cons_node * | cons_cdr_node (struct cons_node *node) |
| Accessor for the next sibling node of a cons node. | |
| struct cons_node * | cons_sub_node (struct cons_node *node) |
| Accessor for the first child node (sub-node) of a cons node. | |
| struct cons_node * | cons_node (struct cons_node *sub, struct cons_node *super) |
| Constructs a cons node with the specified sub-node and new super-node. | |
Defines the structure and functions for cons nodes.
This header file defines the structure of a cons node—a specialised data structure built on top of cons cells. Declares functions for manipulating cons nodes, including accessing parent and child nodes, and constructing a tree of cons nodes.
Definition in file cons_node.h.
| #define CONS_NODE | ( | _cell_, | |
| _head_ | |||
| ) | ((struct cons_node){.cell = (_cell_), .head = (_head_)}) |
Constructs a cons node with the given cell and head.
| cell | The cons cell forming the basis of the node. |
| head | The list of child nodes (sub-nodes). |
Definition at line 22 of file cons_node.h.
A null cons node with no parent and no children.
This macro defines a null cons node, which is a node that has its cell initialised to a null cons cell (with car set to NULL and cdr set to CONS_NIL) and its head set to CONS_NIL, indicating that it has no children. This can be used as a default or placeholder node when constructing a tree of cons nodes.
Definition at line 32 of file cons_node.h.
Accessor for the parent node (super-node) of a cons node.
| node | The cons node to access. |
| Pointer | to the parent node, or NULL if there is no parent. |
Retrieves the parent node from the car field of the cons cell.
Definition at line 36 of file cons_node.c.
Accessor for the next sibling node of a cons node.
| node | The cons node to access. |
NULL if there is no next sibling node. cdr field of the node's cell. Up-casts the cdr field of the cons cell to a pointer to a node. Definition at line 38 of file cons_node.c.
Constructs a cons node with the specified sub-node and new super-node.
| sub | The sub-node to be linked. |
| super | The new super-node to be linked. |
Definition at line 45 of file cons_node.c.
Accessor for the first child node (sub-node) of a cons node.
| node | The cons node to access. |
NULL if there are no child nodes. head field of the cons node. Up-casts the head field to a pointer to a node. Definition at line 40 of file cons_node.c.