[SWI-Prolog 7.x] dict in foreign interface (PL_get_dict_ex and dict_create )

20 views
Skip to first unread message

Oleh

unread,
Jul 9, 2015, 9:36:13 AM7/9/15
to swi-p...@googlegroups.com
Dear all


I think, DICT is a very nice addition in version 7, but what is the reason behind it is not got to SWI-Prolog.h? And thus no PL_ wrappers...

In other words, I'd like to create/modify dictionaries in C code, what is the best way to do it?

Thank you
Oleh

Jan Wielemaker

unread,
Jul 9, 2015, 12:10:05 PM7/9/15
to Oleh, swi-p...@googlegroups.com
On 07/09/15 15:36, Oleh wrote:
> Dear all
>
>
> I think, DICT is a very nice addition in version 7, but what is the
> reason behind it is not got to SWI-Prolog.h? And thus no PL_ wrappers...

There is no real reason except that I don't really know what is the best
interface.

> In other words, I'd like to create/modify dictionaries in C code, what
> is the best way to do it?

So, at this moment all you can do is use pair-lists in C and do the
translation to/from dicts in Prolog. Note that you cannot *modify*
dicts (except for (further) instantiating values).

An obvious API is probably

PL_get_dict(key, dict, value).

The rest is less clear. Use a closure to enumerate the key/values?
Create one from an aray of {key,value} pairs?

Cheers --- Jan

Oleh

unread,
Jul 9, 2015, 12:22:05 PM7/9/15
to swi-p...@googlegroups.com


On Thursday, July 9, 2015 at 6:10:05 PM UTC+2, Jan Wielemaker wrote:
On 07/09/15 15:36, Oleh wrote:
> Dear all
>
>
> I think, DICT is a very nice addition in version 7, but what is the
> reason behind it is not got to SWI-Prolog.h? And thus no PL_ wrappers...

There is no real reason except that I don't really know what is the best
interface.

> In other words, I'd like to create/modify dictionaries in C code, what
> is the best way to do it?

So, at this moment all you can do is use pair-lists in C and do the
translation to/from dicts in Prolog.   Note that you cannot *modify*
dicts (except for (further) instantiating values).

thank you for the hint! I will use it!
 
An obvious API is probably

  PL_get_dict(key, dict, value).

The rest is less clear.  Use a closure to enumerate the key/values?
Create one from an aray of {key,value} pairs?

        Cheers --- Jan

I would suggest:

PL_is_dict
PL_dict_create
PL_dict_pairs
PL_put_dict
PL_get_dict
 

:-)

thank you for the fast reply!
Reply all
Reply to author
Forward
0 new messages