Commit a66e79a7673c0fab989fec5b8f9524edacebca1f

Thomas de Grivel 2024-02-13T10:57:37

env_eval_ident_is_bound

diff --git a/libc3/env.c b/libc3/env.c
index 9ae797e..33725df 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -612,6 +612,23 @@ bool env_eval_ident (s_env *env, const s_ident *ident, s_tag *dest)
   return true;
 }
 
+bool env_eval_ident_is_bound (s_env *env, const s_ident *ident)
+{
+  s_ident tmp_ident;
+  s_tag tmp;
+  assert(env);
+  assert(ident);
+  if (frame_get(env->frame, tmp_ident.sym))
+    return true;
+  ident_init_copy(&tmp_ident, ident);
+  ident_resolve_module(&tmp_ident, env);
+  if (ident_get(&tmp_ident, &env->facts, &tmp)) {
+    tag_clean(&tmp);
+    return true;
+  }
+  return false;
+}
+
 bool env_eval_list (s_env *env, const s_list *list, s_tag *dest)
 {
   s_list *next;
diff --git a/libc3/env.h b/libc3/env.h
index 9ec3ed9..ee5c789 100644
--- a/libc3/env.h
+++ b/libc3/env.h
@@ -53,6 +53,7 @@ bool          env_eval_fn_call (s_env *env, const s_fn *fn,
                                 const s_list *arguments, s_tag *dest);
 bool          env_eval_ident (s_env *env, const s_ident *ident,
                               s_tag *dest);
+bool          env_eval_ident_is_bound (s_env *env, const s_ident *ident);
 bool          env_eval_list (s_env *env, const s_list *list,
                              s_tag *dest);
 bool          env_eval_map (s_env *env, const s_map *map,