Commit 2544241fea9b2ee8a5ab37d46cfe46b2ea27d2cd

Thomas de Grivel 2024-09-05T16:29:08

List.append

diff --git a/.ikc3_history b/.ikc3_history
index 8a99c18..6466141 100644
--- a/.ikc3_history
+++ b/.ikc3_history
@@ -1,4 +1,3 @@
-Facts.with(Facts.env_facts(), [[KC3, :operator, ?]], fn (fact) { puts(fact.object); 1 })
 Facts.with(Facts.env_facts(), quote [[KC3, :operator, op]], fn (fact) { puts(fact.object); 1 })
 op
 op = ?
@@ -97,3 +96,4 @@ EKC3.html_escape("plop <1>")
 Facts.first_with_tags(Facts.env_facts(), KC3, :operator, ?, fn (fact) { fact.object })
 first_operator = Facts.first_with_tags(Facts.env_facts(), KC3, :operator, ?, fn (fact) { fact.object })
 first_operator
+List.append([1, 2, 3], 4)
diff --git a/lib/kc3/0.1/list.kc3 b/lib/kc3/0.1/list.kc3
index 6748287..7dc5b80 100644
--- a/lib/kc3/0.1/list.kc3
+++ b/lib/kc3/0.1/list.kc3
@@ -1,5 +1,7 @@
 defmodule List do
 
+  def append = cfn List "list_init_append" (Result, List, Tag)
+
   def cast = cfn List "list_init_cast" (Result, Sym, Tag)
 
   def has? = cfn Bool "list_has" (List, Tag, Result)
diff --git a/libkc3/list.c b/libkc3/list.c
index 5752aa4..d524d7c 100644
--- a/libkc3/list.c
+++ b/libkc3/list.c
@@ -91,6 +91,25 @@ s_list * list_init_1 (s_list *list, const char *p, s_list *next)
   return list;
 }
 
+s_list ** list_init_append (s_list **list, const s_list * const *src,
+                            const s_tag *tag)
+{
+  const s_list *s;
+  s_list *tmp;
+  s_list **tail;
+  tmp = NULL;
+  tail = &tmp;
+  s = *src;
+  while (s) {
+    *tail = list_new_tag_copy(&s->tag, NULL);
+    tail = &(*tail)->next.data.list;
+    s = list_next(s);
+  }
+  *tail = list_new_tag_copy(tag, NULL);
+  *list = tmp;
+  return list;
+}
+
 s_list ** list_init_cast (s_list **list, const s_sym * const *type,
                           const s_tag *tag)
 {
diff --git a/libkc3/list.h b/libkc3/list.h
index f18d7dc..9dfc8d6 100644
--- a/libkc3/list.h
+++ b/libkc3/list.h
@@ -26,6 +26,8 @@
 void      list_clean (s_list *list);
 s_list  * list_init (s_list *list, s_list *next);
 s_list  * list_init_1 (s_list *list, const char *p, s_list *next);
+s_list ** list_init_append (s_list **list, const s_list * const *src,
+                            const s_tag *tag);
 s_list ** list_init_cast (s_list **list, const s_sym * const *type,
                           const s_tag *tag);
 s_list ** list_init_copy (s_list **list, const s_list * const *src);