gpt4 book ai didi

prolog - "dynamic"序言中的谓词

转载 作者:行者123 更新时间:2023-12-02 02:21:14 25 4
gpt4 key购买 nike

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

:- dynamic likes/2

likes(mary,tom)

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

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

有什么想法吗?

最佳答案

动态谓词按您的预期工作,因此如果它不适合您,则可能存在其他问题。

如果 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;

关于prolog - "dynamic"序言中的谓词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2426678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com