Re: playing around with dicts
Alan Baljeu <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
If person{name:john} is disallowed as a fact, then I
would still be able to assert person_fact(person{name:john}),
right? I see no major concern either way.
The obvious semantics of person{} is an infinitary term
person/INF, where we have a function mapping atoms to numbers.
Then
set_dict(Person, name, john)
is equivalent to
atom_hash(name, Hash), arg(Hash, Person, john).
(We don't /actually/ want people to call arg on a dict,
so in practice this would be verboten.)
Semantics are clear then for all standard predicates
(=, ==, functor, subsumes, etc.), but we still end up
adding a case to our metaprogramming
(if dealing with programs that use dicts).
Alan Baljeu
----- Original Message -----
From: Jan Wielemaker <[email protected]>
To: Richard A. O'Keefe <[email protected]>
Cc: Prolog mailing list <[email protected]>
Sent: Monday, December 16, 2013 3:41:02 AM
Subject: Re: [SWIPL] playing around with dicts
On 12/16/2013 03:05 AM, Richard A. O'Keefe wrote:
>
> On 14/12/2013, at 8:32 AM, Jan Wielemaker wrote:
>> 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}
>
> Why is it? I would expect person{name:john} to match
> any person{.....} as long as ..... included a name:john maplet.
> I would expect person{name:john, age:42} to match any
> person{.....} as long as ..... included a name:john maplet and
> an age:42 maplet. That's how record patterns work in things
> like F#.
Why it is is because how dicts are currently represented. They were not
considered predicate heads, but they are currently a special compound
term, so something happens. If you really want them in a meaningful role
in a predicate head they probably need to be compiled into something
different. Either that or raise a type error.
At this moment, unifying two dicts succeeds only if they can be made the
same. There are several other operations to do partial matching. We can
still change things here.
Cheers --- Jan
_______________________________________________
SWI-Prolog mailing list
[email protected]
https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog