1 /* -*-comment-start: "//";comment-end:""-*-
2 * Mes --- Maxwell Equations of Software
3 * Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
5 * This file is part of Mes.
7 * Mes is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or (at
10 * your option) any later version.
12 * Mes is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Mes. If not, see <http://www.gnu.org/licenses/>.
22 string (scm *x) ///((args . n))
24 char buf[STRING_MAX] = "";
29 assert (s->type == CHAR);
33 return make_string (buf);
37 string_append (scm *x) ///((args . n))
39 char buf[STRING_MAX] = "";
44 assert (s->type == STRING);
45 strcat (buf, s->name);
48 return make_string (buf);
52 list_to_string (scm *x)
54 char buf[STRING_MAX] = "";
59 assert (s->type == CHAR);
64 return make_string (buf);
68 string_length (scm *x)
70 assert (x->type == STRING);
71 return make_number (strlen (x->name));
75 string_ref (scm *x, scm *k)
77 assert (x->type == STRING);
78 assert (k->type == NUMBER);
79 return make_char (x->name[k->value]);
83 substring (scm *x) ///((args . n))
85 assert (x->type == PAIR);
86 assert (x->car->type == STRING);
87 char const *s = x->car->name;
88 assert (x->cdr->car->type == NUMBER);
89 int start = x->cdr->car->value;
91 if (x->cdr->cdr->type == PAIR) {
92 assert (x->cdr->cdr->car->type == NUMBER);
93 assert (x->cdr->cdr->car->value <= end);
94 end = x->cdr->cdr->car->value;
97 strncpy (buf, s+start, end - start);
99 return make_string (buf);
103 number_to_string (scm *x)
105 assert (x->type == NUMBER);
106 char buf[STRING_MAX];
107 sprintf (buf,"%d", x->value);
108 return make_string (buf);
112 string_to_symbol (scm *x)
114 assert (x->type == STRING);
115 return make_symbol (x->name);
119 symbol_to_string (scm *x)
121 assert (x->type == SYMBOL);
122 return make_string (x->name);