Re: Ann: SWI-Prolog 7.1.0
"Richard A. O'Keefe" <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 28/11/2013, at 1:53 AM, Jan Wielemaker wrote:
> On 11/27/2013 06:25 AM, Richard A. O'Keefe wrote:
>
> You are just moving the additional tests elsewhere: into functor/3.
No, I'm not "moving" anything anywhere.
The tests have to be in functor/3 ANYWAY.
We used to have such a simple classification scheme:
A Prolog term X is
- a variable, in which case var(X) succeeds, or
- not a variable, in which case nonvar(X) succeeds.
If nonvar(X) succeeds, then functor(X, F, N) *ALWAYS*
has a solution, where F is a constant and N is a non-negative integer.
N may be
- 0, in which case atomic(X) succeeds and F == X.
This may be further classified as
- atom(X), an atom
- number(X), which breaks down into at least two kinds
- string(X), a string, in some systems
- some other kind of atomic data, such as (in Interlisp-D)
references to GUI widgets, Lisp arrays, &c
- > 0, in which case compound(X) succeeds and atom(F) succeeds.
So meta-logical code had the shape
p(X, ...) :-
( var(X) ->
; functor(X, F, N),
do something with F
do something with arg(I, X, A) for I in 1..N
).
That's it. functor/3 was and remains a *core* metalogical
operation, and functor(X, X, 0) succeeding for *all* atomic(X)
was and remains a *key* non-accidental not-just-a-relic
*highly prized* property that drastically simplifies much
meta-logical code.
I no longer recall if there was a time when functor(42, _, _)
didn't succeed. I do recall that when I discovered at
Edinburgh that it _did_ succeed I found that it simplified
my meta-logical code so much that it just wasn't funny.
>
> Changing these relics breaks too much (I tried).
That's nature trying to tell you that making f() a new kind of
term was a bad idea.
Hands up everyone who has written a predicate to find the
least general generalisation of two terms (assuming no cycles)?
It can't just be me.
Guess what predicate that depends on?