Prolog existence_error following Seven Languages in Seven Weeks

前端 未结 1 958
逝去的感伤
逝去的感伤 2021-02-05 02:41

I\'m just following the book Seven Languages in Seven Weeks.

I\'ve installed gprolog in my Mac machine using command port install gprolog-devel and run firs

1条回答
  •  一整个雨季
    2021-02-05 03:20

    The interactive gprolog interpreter runs queries against a loaded list of predicates, that is why you get the existence_error exception. You will have to load your predicates into it, either by using an IDE that does the loading for you or doing it manually.

    Here's one approach:

    | ?- [user].
    compiling user for byte code...
    likes(wallace, cheese).
    likes(grommit, cheese).
    likes(wendolene, sheep).
    
    friend(X, Y) :- \+(X = Y), likes(X, Z), likes(Y, Z).
    
    * Press Ctrl-D to end input. *
    user compiled, 6 lines read - 909 bytes written, 15538 ms
    
    yes
    | ?- friend(wallace,grommit).
    
    yes
    | ?- friend(wallace,wendolene).
    
    no
    

    The gprolog manual writes about this in the chapter Consulting a Prolog program

    0 讨论(0)
提交回复
热议问题