Re: Ann: SWI-Prolog 7.1.0
Nicos Angelopoulos (Univ of York) <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <20131125224938.76fab828@naga> |
Dear Jeff, On Mon, 25 Nov 2013 13:13:35 +1100 Jeff Schultz <[email protected]> wrote: > 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. > > > 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 There is at least one more way to proceed here, if i am not misinterpreting your alternatives. functor/3 could be made to fail/except on atoms. It seems to me more natural for functor/3 to work on compounds. This would break some code, but it might regularise the language. I am not at all certain myself what is best here, but failing to see this alternative altogether does not feel right. It is likely that I am (doubly) biased here. I don't think I have much code that depends on functor( Atomic, Name, 0 ) and if i have some I would n't mind changing it. Second bias is that code that is not maintained, should not dictate. I am probably missing something obvious, so I would appreciate some examples in which one would want to use functor/3 with atomic in its first argument. Certainly this is not a decision SWI should-have-to/can take on its own, maybe people that are involved in standarisation have a view on this and can move this forward. Nicos Angelopoulos --- http://stoics.org.uk/~nicos/