Commit 8dab471ff6793cd37a1e8f8a6198518615eb4a42

Thomas de Grivel 2024-08-17T13:26:54

facts_with_tuple

diff --git a/lib/kc3/0.1/facts.kc3 b/lib/kc3/0.1/facts.kc3
index d3bc699..8ef12d7 100644
--- a/lib/kc3/0.1/facts.kc3
+++ b/lib/kc3/0.1/facts.kc3
@@ -23,6 +23,7 @@ defmodule Facts do
     Fn, Result)
 
   # with_tuple(facts, tuple, fn (fact) {result}) -> result
-  #def with_tuple = cfn Tag "kc3_facts_with_tuple" (Facts, Tuple, Fn, Result)
+  def with_tuple = cfn Tag "kc3_facts_with_tuple" (Facts, Tuple, Fn,
+    Result)
 
 end
diff --git a/libkc3/kc3.c b/libkc3/kc3.c
index 966ac45..a877cef 100644
--- a/libkc3/kc3.c
+++ b/libkc3/kc3.c
@@ -198,6 +198,23 @@ s_tag * kc3_facts_with_tags (s_facts *facts, s_tag *subject,
                              object, callback, dest);
 }
 
+s_tag * kc3_facts_with_tuple (s_facts *facts, s_tuple *tuple,
+                              s_fn *callback, s_tag *dest)
+{
+  assert(facts);
+  assert(tuple);
+  assert(callback);
+  assert(dest);
+  if (tuple->count < 3) {
+    err_puts("kc3_facts_with_tuple: tuple count < 3");
+    assert(! "kc3_facts_with_tuple: tuple count < 3");
+    return NULL;
+  }
+  return env_facts_with_tags(&g_kc3_env, facts, tuple->tag,
+                             tuple->tag + 1, tuple->tag + 2, callback,
+                             dest);
+}
+
 s_tag * kc3_quote_cfn (const s_sym **sym, s_tag *dest)
 {
   assert(sym);
diff --git a/test/ikc3/facts_with_tuple.kc3 b/test/ikc3/facts_with_tuple.kc3
new file mode 100644
index 0000000..3bad1f7
--- /dev/null
+++ b/test/ikc3/facts_with_tuple.kc3
@@ -0,0 +1,8 @@
+quote Facts.with_tuple(Facts.env_facts(), {KC3, :operator, ?}, fn (fact) {
+  puts(fact.object)
+  void
+})
+Facts.with_tuple(Facts.env_facts(), {KC3, :operator, ?}, fn (fact) {
+  puts(fact.object)
+  void
+})
diff --git a/test/ikc3/facts_with_tuple.out.expected b/test/ikc3/facts_with_tuple.out.expected
new file mode 100644
index 0000000..03807f0
--- /dev/null
+++ b/test/ikc3/facts_with_tuple.out.expected
@@ -0,0 +1,30 @@
+Facts.with_tuple(Facts.env_facts(), {KC3, :operator, ?}, fn (fact) { puts(fact.object); void })
+operator_eq
+operator_gt
+operator_lt
+operator_or
+operator_add
+operator_and
+operator_bor
+operator_div
+operator_gte
+operator_lte
+operator_mod
+operator_mul
+operator_neg
+operator_not
+operator_pin
+operator_sub
+operator_addi
+operator_band
+operator_bnot
+operator_bxor
+operator_equal
+operator_paren
+operator_not_eq
+operator_require
+operator_brackets
+operator_defstruct
+operator_shift_left
+operator_shift_right
+void
diff --git a/test/ikc3/facts_with_tuple.ret.expected b/test/ikc3/facts_with_tuple.ret.expected
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/test/ikc3/facts_with_tuple.ret.expected
@@ -0,0 +1 @@
+0