« Return to Thread: Inconsistent behaviour of assert/2

Re: Inconsistent behaviour of assert/2

by Jan Wielemaker-3 :: Rate this Message:

Reply to Author | View in Thread

Hi Günter,

On Saturday 27 June 2009 20:20:27 Günter Kniesel wrote:

> 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.

Done.

> 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)

I guess this makes sense, but changing that would break a lot of old
code because assert/2 gets a different meaning. Although assert/2 is not
part of ISO (AFAIK), it has been along for a long time and is probably
still actively used.

        Cheers --- Jan


_______________________________________________
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