Commit 8802b04a4feab348271a511d88846ad07436a6a3

Thomas de Grivel 2024-09-29T17:04:45

wip env_facts_with

diff --git a/.ikc3_history b/.ikc3_history
index 0147367..fdac7e3 100644
--- a/.ikc3_history
+++ b/.ikc3_history
@@ -1,13 +1,3 @@
-?0x4c21af5a1f0
-Str.split("/plop/hop/", "/")
-Str.split("/1/2/3/", "/")
-List.join(Str.split("/1/2/3/", "/"), "/")
-HTTP.mime_type(".txt")
-HTTP.mime_type("plop.txt")
-HTTP.mime_type("txt")
-HTTP.mime_type_load("httpd/fx/config/mime.types")
-HTTP.mime_type("txt")
-HTTP.mime_type(".txt")
 HTTP.mime_type("pplop.txt")
 HTTP.mime_type("txt")
 File.ext("Plop.html")
@@ -97,3 +87,13 @@ to_lisp(quote a = ?; a <- 1; a)
 Facts.database()
 a = Facts.database()
 (Facts) a
+a = Facts.env_db()
+(Facts) a
+db = ^ a
+(Facts) db
+Facts.with(db, [[KC3, :operator, op = ?], [op, :sym, sym = ?]], fn (fact) { puts("#{op} #{sym}") })
+op
+sym
+Facts.with(db, [[KC3, :operator, op = ?], [op, :sym, sym = ?]], fn (fact) { puts("#{op} #{sym}") })
+Facts.with(Facts.env_db(), [[KC3, :operator, op = ?], [op, :sym, sym = ?]], fn (fact) { puts("#{op} #{sym}") })
+Facts.with(Facts.env_db(), [[KC3, :operator, op = ?], [op, :sym, sym = ?]], fn (fact) { puts("#{inspect(op)} #{inspect(sym)}") })
diff --git a/ikc3/.ikc3_history b/ikc3/.ikc3_history
index 0147367..cb2b4d8 100644
--- a/ikc3/.ikc3_history
+++ b/ikc3/.ikc3_history
@@ -1,15 +1,3 @@
-?0x4c21af5a1f0
-Str.split("/plop/hop/", "/")
-Str.split("/1/2/3/", "/")
-List.join(Str.split("/1/2/3/", "/"), "/")
-HTTP.mime_type(".txt")
-HTTP.mime_type("plop.txt")
-HTTP.mime_type("txt")
-HTTP.mime_type_load("httpd/fx/config/mime.types")
-HTTP.mime_type("txt")
-HTTP.mime_type(".txt")
-HTTP.mime_type("pplop.txt")
-HTTP.mime_type("txt")
 File.ext("Plop.html")
 HTTP.mime_type(File.ext("Plop.html"))
 (Str) HTTP.mime_type(File.ext("Plop.html"))
@@ -97,3 +85,15 @@ to_lisp(quote a = ?; a <- 1; a)
 Facts.database()
 a = Facts.database()
 (Facts) a
+a = Facts.env_db()
+(Facts) a
+db = ^ a
+(Facts) db
+Facts.with(db, [[KC3, :operator, op = ?], [op, :sym, sym = ?]], fn (fact) { puts("#{op} #{sym}") })
+op
+sym
+Facts.with(db, [[KC3, :operator, op = ?], [op, :sym, sym = ?]], fn (fact) { puts("#{op} #{sym}") })
+Facts.with(Facts.env_db(), [[KC3, :operator, op = ?], [op, :sym, sym = ?]], fn (fact) { puts("#{op} #{sym}") })
+Facts.with(Facts.env_db(), [[KC3, :operator, op = ?], [op, :sym, sym = ?]], fn (fact) { puts("#{inspect(op)} #{inspect(sym)}") })
+(a = ?) <- 1; a
+a
diff --git a/lib/kc3/0.1/facts.kc3 b/lib/kc3/0.1/facts.kc3
index 0f0b358..a2e5599 100644
--- a/lib/kc3/0.1/facts.kc3
+++ b/lib/kc3/0.1/facts.kc3
@@ -23,8 +23,8 @@ defmodule Facts do
 
   def delete = cfn Void "facts_delete" (Facts)
 
-  # env_facts() -> facts
-  def env_facts = cfn Ptr "kc3_env_facts" (Result)
+  # env_db() -> facts
+  def env_db = cfn Ptr "kc3_env_db" (Result)
 
   # with_tags(facts, subject, predicate, object,
   #           fn (fact) {result}) -> result
diff --git a/libkc3/buf_inspect.c b/libkc3/buf_inspect.c
index 71cb294..e66ffc8 100644
--- a/libkc3/buf_inspect.c
+++ b/libkc3/buf_inspect.c
@@ -2201,7 +2201,7 @@ sw buf_inspect_ident_size (s_pretty *pretty, const s_ident *ident)
   sw r;
   sw result = 0;
   assert(ident);
-  if (ident->module) {
+  if (ident->module && ident->module != g_kc3_env.current_defmodule) {
     if ((r = buf_inspect_sym_size(pretty, &ident->module)) < 0)
       return r;
     result += r;
diff --git a/libkc3/kc3.c b/libkc3/kc3.c
index 7b0184d..4ade011 100644
--- a/libkc3/kc3.c
+++ b/libkc3/kc3.c
@@ -165,7 +165,7 @@ void ** kc3_dlopen (const s_str *path, void **dest)
   return dest;
 }
 
-s_facts ** kc3_env_facts (s_facts **dest)
+s_facts ** kc3_env_db (s_facts **dest)
 {
   *dest = &g_kc3_env.facts;
   return dest;
diff --git a/libkc3/kc3_main.h b/libkc3/kc3_main.h
index d35179c..70a5518 100644
--- a/libkc3/kc3_main.h
+++ b/libkc3/kc3_main.h
@@ -63,7 +63,7 @@ s_tag *      kc3_defoperator (const s_sym **name, const s_sym **sym,
                               s_tag *dest);
 s_tag *      kc3_defstruct (const s_list * const *spec, s_tag *dest);
 void **      kc3_dlopen (const s_str *path, void **dest);
-s_facts **   kc3_env_facts (s_facts **dest);
+s_facts **   kc3_env_db (s_facts **dest);
 sw           kc3_errno (void);
 void         kc3_exit (sw code);
 s_tag *      kc3_facts_collect_with_tags (s_facts *facts,
diff --git a/libkc3/str.c b/libkc3/str.c
index e2853f5..592ae89 100644
--- a/libkc3/str.c
+++ b/libkc3/str.c
@@ -367,6 +367,8 @@ s_str * str_init_cast (s_str *str, const s_sym * const *type,
     return str_init_character(str, tag->data.character);
   case TAG_FN:
     return str_init_fn(str, &tag->data.fn);
+  case TAG_IDENT:
+    return str_init_ident(str, &tag->data.ident);
   case TAG_LIST:
     return str_init_list(str, (const s_list * const *) &tag->data.list);
   case TAG_MAP:
@@ -572,6 +574,7 @@ s_str * str_init_ftime (s_str *str, s_time *time, const s_str *format)
   return NULL;
 }
 
+DEF_STR_INIT_STRUCT(ident)
 DEF_STR_INIT_PTR(list, const s_list * const *)
 DEF_STR_INIT_STRUCT(map)
 DEF_STR_INIT_PTR(ptr, const u_ptr_w *)
diff --git a/libkc3/str.h b/libkc3/str.h
index a5985f8..24b7285 100644
--- a/libkc3/str.h
+++ b/libkc3/str.h
@@ -56,6 +56,7 @@ s_str * str_init_empty (s_str *str);
 s_str * str_init_f (s_str *str, const char *fmt, ...);
 PROTOTYPE_STR_INIT_STRUCT(fn);
 s_str * str_init_ftime (s_str *str, s_time *time, const s_str *format);
+PROTOTYPE_STR_INIT_STRUCT(ident);
 PROTOTYPE_STR_INIT(list, const s_list * const *);
 PROTOTYPE_STR_INIT_STRUCT(map);
 PROTOTYPE_STR_INIT(ptr, const u_ptr_w *);
diff --git a/libkc3/tag.c b/libkc3/tag.c
index 5f4ea73..2b4260c 100644
--- a/libkc3/tag.c
+++ b/libkc3/tag.c
@@ -855,7 +855,10 @@ bool * tag_is_unbound_var (const s_tag *tag, bool *dest)
     assert(! "tag_is_unbound_var: NULL tag");
     return NULL;
   }
-  *dest = tag->type == TAG_VAR;
+  *dest = (tag->type == TAG_VAR &&
+           tag->data.var.ptr &&
+           tag->data.var.ptr->type == TAG_VAR &&
+           tag->data.var.ptr->data.var.ptr == tag->data.var.ptr);
   return dest;
 }