Serene Runtime 1.0.0
C runtime for the Serene programming language
Loading...
Searching...
No Matches
lists.c
Go to the documentation of this file.
1/* -*- C -*-
2 * Serene programming language
3 * Copyright (C) 2019-2026 Sameer Rahmani <[email protected]>
4 *
5 * This library is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library. If not, see <https://www.gnu.org/licenses/>.
17 */
18
20
21#include "serene/rt/context.h"
22
24 srn_pair_t *p = ALLOC(ctx, srn_pair_t);
25 p->left = left;
26 p->right = right;
27
28 return (srn_value_t)p | TAG_LIST;
29}
30
32 srn_list_t *l = ALLOC(ctx, srn_list_t);
33 l->head = nullptr;
34 l->length = 0;
35}
36
37/// Add the given value `v` to the front of the list and returns the new list.
38[[gnu::nonnull(1)]] srn_value_t srn_conj_list(srn_context_t *ctx, srn_list_t *head, srn_value_t v);
#define ALLOC(ctx, T)
Definition context.h:82
srn_value_t srn_make_list(srn_context_t *ctx)
Create a new list and empty list.
Definition lists.c:31
srn_value_t srn_make_pair(srn_context_t *ctx, srn_value_t left, srn_value_t right)
Definition lists.c:23
srn_value_t srn_conj_list(srn_context_t *ctx, srn_list_t *head, srn_value_t v)
Add the given value v to the front of the list and returns the new list.
Since all the values are immutable and persistent.
Definition lists.h:36
srn_pair_t * head
Definition lists.h:38
size_t length
Definition lists.h:39
srn_value_t right
Definition lists.h:31
srn_value_t left
Definition lists.h:30