Re: playing around with dicts

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
Hi Michael,

Thanks for the feedback.

On 12/13/2013 06:57 PM, Michael Hendricks wrote:
> I've been playing with dicts in V7.  Here are some observations/questions.
>  This is all done with V7.1.3 on OS X Mavericks.
>
> ?- assert(person{name:john}).
>
> gives a segfault.  Full trace is at https://gist.github.com/mndrix/7947317
>
> I was glad to see that dicts are allowed as facts and clause heads.
>  However, calling listing/0 on such programs gives an error about
> sub_atom/5.  See https://gist.github.com/mndrix/7947389

I think that dicts being allowed as clause head is more a coincident
resulting from the fact that they currently are implemented as ordinary
compound terms with a reserved symbol as functor. I think that should
not be allowed. For one thing,

	person{name:john}

is a different predicate than

	person{name:john, age:42}

I'd also like to have the option to make dicts completely distinct from
compounds.  For this type of usage, the ECLiPSe struct approach would
be more interesting.

> Section 5.4 of the manual says, "If a dict is written, the keys are written
> according to the standard order of terms".  Do we want to commit to that
> behavior so early in the design?  If the implementation changes to
> something based on hashing, it could be expensive to generate sorted
> output.  We can always commit to sorted output later.

I consider allowing them as predicate heads a more involved restriction.
Dicts are already not stored in the standard order of terms, but in the
order of internal handles. So, printing already needs to (re-)sort them.
Having predictable printed output is (IMHO) a nice property.

	Cheers --- Jan

... happy after doing a bit of application programming using dics today.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.