2

I am really not clear about the difference between assert and asserta, as when I was trying to make a fibonacci program in linear time. Asserta worked really fast whereas assert gave me an error.

Can some one explain why asserta is better than assert in some cases?

Thanks!

false
  • 10,264
  • 13
  • 101
  • 209
Harshdeep Singh
  • 327
  • 1
  • 5
  • 18

1 Answers1

3

In not a question of being better. The assert/1 predicate is legacy and nowadays usually an alias to the assertz/1 predicate. The difference between the asserta/1 and assertz/1 predicates is that the first asserts a clause as the first one for a dynamic predicate while the second asserts a clause as the last one for a dynamic predicate.

Paulo Moura
  • 18,373
  • 3
  • 23
  • 33
  • 2
    the intention of the naming could be to see the clauses of a predicate as a ordered list A to Z like an ordered alphabet, and then assert"A" is prepending, and assert"Z" is appending additional clauses to that list (dynamic predicate)? – Hartmut Pfarr Jan 29 '22 at 14:55