summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index 78e77f57..e71b87cd 100644
--- a/lib.c
+++ b/lib.c
@@ -307,6 +307,29 @@ val sixth(val cons)
return car(cdr(cdr(cdr(cdr(cdr(cons))))));
}
+val listref(val list, val ind)
+{
+ if (lt(ind, zero))
+ return nil;
+ for (; gt(ind, zero); ind = minus(ind, one))
+ list = cdr(list);
+ return car(list);
+}
+
+val *listref_l(val list, val ind)
+{
+ val olist = list;
+ val oind = ind;
+
+ for (; gt(ind, zero) && list; ind = minus(ind, one))
+ list = cdr(list);
+ if (consp(list))
+ return car_l(list);
+
+ uw_throwf(error_s, lit("~s has no assignable location at ~s"),
+ olist, oind, nao);
+}
+
val *tail(val cons)
{
while (cdr(cons))
@@ -3793,6 +3816,20 @@ val obj_pprint(val obj, val out)
return obj;
}
+val tostring(val obj)
+{
+ val ss = make_string_output_stream();
+ obj_print(obj, ss);
+ return get_string_from_stream(ss);
+}
+
+val tostringp(val obj)
+{
+ val ss = make_string_output_stream();
+ obj_pprint(obj, ss);
+ return get_string_from_stream(ss);
+}
+
void init(const wchar_t *pn, mem_t *(*oom)(mem_t *, size_t),
val *stack_bottom)
{