Re: Ann: SWI-Prolog 7.1.0
Jeff Schultz <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 24/11/2013 03:49, Jan Wielemaker wrote:
> On 11/22/2013 10:48 PM, Abramo Bagnara wrote:
>> ?- A1 = a(), functor(A1, a, 0), functor(A2, a, 0), writeln(A1-A2), A1 = A2.
>> a()-a
>> false.
>>
>> This behavior is indeed very surprising for me... Is it deliberate?
>
> Yes. I tried changing functor/3 (and =../2), but the compatibility
> consequences are too involved and often hard to debug. Therefore I left
> functor/3 and =../2 alone and added compound_name_arity/3 and
> compound_name_arguments/3. You need these if you want to do
There appear to be four ways a() could be handled by functor/3 and the like:
(1) As above. functor(a(), a, 0) and functor(a, a, 0) succeed, and
functor(A, a, 0) succeeds once with A = a.
(2) As (1), but functor(A, a, 0) succeeds twice with A = a or A = a().
(3) functor(a(), F, N) fails.
(4) functor(a(), F, N) raises a domain_error.
I don't think I like (1) at all. Currently working code that copies
(and modifies) terms will now silently change a() into a in many places.
(2) introduces non-determinism where we've not had it before, and will
be painful to implement efficiently. (Or at least, I will find it
difficult to implement efficiently.) I think it would be a poor choice.
(3) will probably cause unnecessary surprise, and I don't like it either.
(4) is probably the safest. Any code it breaks will likely be broken by
the new a() terms anyway, and the breakage will at least be obvious.
> term manipulation that is robust against a(). a() mainly plays
> a role in user-defined functions on maps and special purpose
> notation for DSLs. This implies you mostly need to be aware
> of this in some parts of the Prolog infrastructure (e.g,
> goal expansion) and code that manages DSL expressions that use
> this.
>
> In my view, this is a notation that can make the representation
> of some DSLs much more understandable and you don't need to use
> it in other contexts. That said, I like
>
> maplist(length(), ListOfLists, Lengths)
>
> more than
>
> maplist(length, ListOfLists, Lengths)
I'm afraid that I don't see any use for it sufficient for such a large
change to the Prolog data model, and it will complicate a lot of my
code, but if we're to have it, could we try out (4) please?
Jeff Schultz