6

如果我想使规则动态化,以便在加载数据库文件后使用断言,我该怎么做?我现在正在使用 XSB Prolog,文件是这样的:

:- dynamic likes/2

likes(mary,tom)

当我尝试使用 XSB 查阅文件时,出现错误:

? consult('D:\file.P).
not permitted to assert to static predicatelikes/2
forward continuation...blahblah

有任何想法吗?

4

1 回答 1

8

动态谓词按您的预期工作,所以如果它不适合您,那就有别的问题了。

如果 test.P 看起来像这样:

:- dynamic likes/2.

likes(mary,tom).

可以查阅,然后可以断言更多的likes/2 事实:

XSB Version 3.2 (Kopi Lewak) of March 15, 2009
[i686-pc-linux-gnu; mode: optimal; engine: slg-wam; scheduling: local; word size: 32]

| ?- consult('test.P').
[Compiling ./test]
[test compiled, cpu time used: 0.0440 seconds]
[test loaded]

yes
| ?- assert(likes(mary, bob)).

yes
| ?- likes(X,Y).

X = mary
Y = tom;

X = mary
Y = bob;
于 2010-03-12T00:16:05.633 回答