diff --git a/lib/kc3/0.1/facts.kc3 b/lib/kc3/0.1/facts.kc3
index cba238d..886d031 100644
--- a/lib/kc3/0.1/facts.kc3
+++ b/lib/kc3/0.1/facts.kc3
@@ -37,6 +37,9 @@ defmodule Facts do
# returns true if fact was removed or is already absent
def remove_tags = cfn Bool "kc3_facts_remove_tags" (Facts, Tag, Tag, Tag, Result)
+ # returns true if fact was added or is already present
+ def replace_tags = cfn Bool "kc3_facts_replace_tags" (Facts, Tag, Tag, Tag, Result)
+
# with(facts, [[?, ?, ?]], fn (fact) {result}) -> result
def with = cfn Tag "kc3_facts_with" (Facts, List, Fn, Result)
diff --git a/lib/kc3/0.1/map.facts b/lib/kc3/0.1/map.facts
index ee6b75a..5b7cc14 100644
--- a/lib/kc3/0.1/map.facts
+++ b/lib/kc3/0.1/map.facts
@@ -2,10 +2,12 @@
version: 1}
add {Map, :is_a, :module}
add {Map, :symbol, Map.cast}
-add {Map, :symbol, Map.map}
-add {Map, :symbol, Map.to_list}
replace {Map.cast, :symbol_value, cfn Map "map_init_cast" (Tag, Result)}
+add {Map, :symbol, Map.map}
replace {Map.map, :symbol_value, cfn List "map_map" (Map, Fn, Result)}
+add {Map, :symbol, Map.to_list}
replace {Map.to_list, :symbol_value, fn (%{} = map) {
Map.map(map, fn (k, v) { {k, v} })
}}
+add {Map, :symbol, Map.put}
+replace {Map.put, :symbol_value, cfn Map "map_put" (Map, Tag, Tag, Result)}
diff --git a/libkc3/kc3.c b/libkc3/kc3.c
index 2aa6b14..a1c08a0 100644
--- a/libkc3/kc3.c
+++ b/libkc3/kc3.c
@@ -273,6 +273,19 @@ bool * kc3_facts_remove_tags (s_facts *facts, const s_tag *subject,
return dest;
}
+bool * kc3_facts_replace_tags (s_facts *facts,
+ const s_tag *subject,
+ const s_tag *predicate,
+ const s_tag *object,
+ bool *dest)
+{
+ const s_fact *fact;
+ if (! (fact = facts_replace_tags(facts, subject, predicate, object)))
+ return NULL;
+ *dest = true;
+ return dest;
+}
+
s_tag * kc3_facts_with (s_facts *facts, s_list **spec,
s_fn *callback, s_tag *dest)
{
diff --git a/libkc3/kc3_main.h b/libkc3/kc3_main.h
index fd9418e..7a474bc 100644
--- a/libkc3/kc3_main.h
+++ b/libkc3/kc3_main.h
@@ -82,6 +82,11 @@ bool * kc3_facts_remove_tags (s_facts *facts,
const s_tag *predicate,
const s_tag *object,
bool *dest);
+bool * kc3_facts_replace_tags (s_facts *facts,
+ const s_tag *subject,
+ const s_tag *predicate,
+ const s_tag *object,
+ bool *dest);
s_tag * kc3_facts_with (s_facts *facts, s_list **spec,
s_fn *callback, s_tag *dest);
s_tag * kc3_facts_with_tags (s_facts *facts, s_tag *subject,
diff --git a/libkc3/map.c b/libkc3/map.c
index 274ee12..8dc0eda 100644
--- a/libkc3/map.c
+++ b/libkc3/map.c
@@ -364,7 +364,7 @@ s_map * map_sort (s_map *map)
return map;
}
-s_map * map_update (const s_map *map, const s_tag *key,
+s_map * map_put (const s_map *map, const s_tag *key,
const s_tag *value, s_map *dest)
{
s_map tmp = {0};
@@ -384,7 +384,7 @@ s_map * map_update (const s_map *map, const s_tag *key,
return NULL;
}
-s_map * map_update_list (const s_map *map, const s_list *alist, s_map *dest)
+s_map * map_put_list (const s_map *map, const s_list *alist, s_map *dest)
{
const s_list *i = NULL;
s_map tmp = {0};
@@ -394,8 +394,8 @@ s_map * map_update_list (const s_map *map, const s_list *alist, s_map *dest)
while (i) {
assert(i->tag.type == TAG_TUPLE && i->tag.data.tuple.count == 2);
if (i->tag.type != TAG_TUPLE || i->tag.data.tuple.count != 2) {
- err_puts("map_update_list: not an associative list");
- assert(! "map_update_list: not an associative list");
+ err_puts("map_put_list: not an associative list");
+ assert(! "map_put_list: not an associative list");
goto ko;
}
if (! map_set(&tmp, i->tag.data.tuple.tag, i->tag.data.tuple.tag + 1))
diff --git a/libkc3/map.h b/libkc3/map.h
index f2f9996..495a41a 100644
--- a/libkc3/map.h
+++ b/libkc3/map.h
@@ -43,9 +43,9 @@ const s_sym ** map_get_type (const s_map *map, const s_tag *key,
const s_sym **dest);
const s_sym ** map_get_var_type (const s_map *map, const s_tag *key,
const s_sym **dest);
-s_map * map_update (const s_map *map, const s_tag *key,
- const s_tag *value, s_map *dest);
-s_map * map_update_list (const s_map *map, const s_list *alist,
- s_map *dest);
+s_map * map_put (const s_map *map, const s_tag *key,
+ const s_tag *value, s_map *dest);
+s_map * map_put_list (const s_map *map, const s_list *alist,
+ s_map *dest);
#endif /* LIBKC3_MAP_H */