Is there a preferred way to efficiently create dicts in foreign C code?
Of course, I can create a list of pairs and call dict_pairs/3
, or construct a compound term (BTW, why SWI-Prolog.h
does not define ATOM_dict?):
#define ATOM_dict (_PL_atoms()[2])
functor_t fDict = PL_new_functor(ATOM_dict, 3);
term_t tTag = PL_new_term_ref();
term_t tVal = PL_new_term_ref();
PL_unify_integer(tVal, 42);
term_t tKey = PL_new_term_ref();
PL_unify_chars(tKey, PL_ATOM, 5, "mykey");
term_t tDict = PL_new_term_ref();
PL_cons_functor(tDict, fDict, tTag, tVal, tKey);
But should there be a better way?