Prolog - ASSERT and RETRACT

前端 未结 1 713
一个人的身影
一个人的身影 2020-12-05 13:52

I was wondering, I am aware you can use assert to add facts or rules or whatever if you have declared the predicate to be -:dynamic, but this only

相关标签:
1条回答
  • 2020-12-05 14:05

    I can suggest you a very simple way of doing this.

    1 ?- assert(a(1)).
    true.
    
    2 ?- assert(a(2)).
    true.
    
    3 ?- assert(a(3)).
    true.
    
    4 ?- a(A).
    A = 1 ;
    A = 2 ;
    A = 3.
    
    5 ?- tell('a_db.txt'), listing(a), told.
    true.
    

    Then close session, reopen.

    1 ?- a(A).
    ERROR: toplevel: Undefined procedure: a/1 (DWIM could not correct goal)
    2 ?- ['a_db.txt'].
    % a_db.txt compiled 0.00 sec, 516 bytes
    true.
    
    3 ?- a(A).
    A = 1 ;
    A = 2 ;
    A = 3.
    
    4 ?- listing(a).
    :- dynamic a/1.
    
    a(1).
    a(2).
    a(3).
    
    true.
    
    0 讨论(0)
提交回复
热议问题