Re: Some thoughts on dicts in SWIPL 7
Jan Wielemaker <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 02/18/2014 11:17 AM, Carlo Capelli wrote:
> I also like dicts syntax, just missing semantic highlighting for the
> keys when used in functional notation.
> Given the small visual difference between dots and commas, porting
> cluttered code can result in difficult to spot errors.
>
> Is a patch to library(prolog_colour) underway ? Otherwise, I could try
> to do...
I had no plans, but I think it can be useful. I still dislike the bold
keys used at the moment. If you can find a nice colour scheme, please
send a patch.
Didn't have time to play enough with the new toys :-(
Cheers --- Jan
P.s. still thinking whether psi-terms can/should be implemented op top
of attvars and what that should look like ...
The start can be like this:
:- module(psi,
[ psi/2
]).
psi(Term, Features) :-
dict_create(Dict, psi, Features),
put_attr(Term, psi, Dict).
attr_unify_hook(Dict1, PSI2) :-
get_attr(PSI2, psi, Dict2),
Dict1 >:< Dict2,
put_dict(Dict1, Dict2, Union),
put_attr(PSI2, psi, Union).
Now you can do:
15 ?- psi(T1, [a:1, b:2]), psi(T2, [a:X, c:3]), T1 = T2.
T1 = T2,
X = 1,
put_attr(T2, psi, psi{a:1, b:2, c:3}).
Functionality-wise, this seems be close to what we want. Only the way to
create PSIs and to print them is a bit awkward. There are some
questions:
- Is this really doing what we want?
- How to read and write psi-terms?
- How to realise the create/print technically?
- What other functionality do we need on them?