« Return to Thread: Inconsistent behaviour of assert/2

Inconsistent behaviour of assert/2

by Günter Kniesel :: Rate this Message:

Reply to Author | View in Thread

Dear all,

my students were confused by the following, arguably undesired behaviour
of assert/2. Expecting that assert mirrors clause(Head,Body) they
tried to use it as assert(Head,Body) and where surprised to get
the following:

17 ?- assert(a,b).
false.

18 ?- listing(a).
:- dynamic user:a/0.

user:a.

true.

The above behaviour (claiming assertion failed but nevertheless asserting
the clause) is highly confusing.

I would suggest that the implementation of assert/2 should be
changed so that if the second argument (the clause reference)
is not a free variable, then the assertion is not performed.

However, that would only partly remove the cause of the confusion,
which, in the first place, is the non-uniform semantics of the
arguments to assert and clause. So I'm curious to know why
there isn't an assert(Head,Body) that mirrors clause(Head,Body)?

Why does "clause" hide the nature of clauses as :-/2 terms whereas
"assert" cannot even be used without understanding that clauses are
:-/2 terms?

This might have historical reasons but, in hindsight, is it a good
design that one should pursue further? Uniformity and consistency
in a language design have many advantages. Easier learning by novices
is just one of them.

Note that, with a symmetric behaviour of clause/2 and assert/3 their
versions with an additional clause reference argument would also
mirror each other:
   - clause(Head,Body,Reference) and
   - assert(Head,Body,Reference)

Looking forward to your opinions,
Günter

--------------------------------------------------------------------
Dr. Günter Kniesel                    http://www.cs.uni-bonn.de/~gk/
Institut für Informatik III                        gk@...
Universität Bonn
Römerstr. 164 (Raum A107)                      Tel (+49 228) 73-4511
D-53117 Bonn                                   Fax (+49 228) 73-4382
_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog

 « Return to Thread: Inconsistent behaviour of assert/2