我正在使用clause/2
在编译器中转换某些Prolog子句。我需要用它的主体替换每个子句的开头,但是clause/2
有时并没有以其最初编写的方式扩展该子句。
在这里,clause/2
将clause/2
扩展为demo(A,B)
,而不是扩展其原始定义:
\+ (call(A),\+call(B))
还有另一种方法来扩展子句,而无需修改包含:- use_module(prolog_to_minizinc).
:- initialization(main).
main :-
writeln(forall(A,B)),
clause(demo(A,B),Clause),
writeln(Clause).
demo(A,B) :-
forall(A,B).
的子句吗?
forall/2
目标的不必要扩展是由于SWI-Prolog在启动时加载了forall/2
。该库提供了library(apply_macros)
和其他谓词的扩展代码。查找forall/2
的加载方式并非易事,因为在library(apply_macros)
文件中将verbose_autoload
标志设置为true
并不会显示启动时正在自动加载的所有库。在我的笔记本电脑上,使用SWI-Prolog(~/.config/swi-prolog/init.pl
)的当前开发git版本:
8.1.21-82-ge6e1d5376-DIRTY
文件?- current_module(apply_macros).
true.
?- module_property(apply_macros, P).
P = class(library) ;
P = file('/Users/pmoura/lib/swipl/library/apply_macros.pl') ;
P = line_count(36) ;
P = exports([expand_phrase/2, expand_phrase/4]) .
?- source_file_property('/Users/pmoura/lib/swipl/library/apply_macros.pl', P).
P = modified(1547476368.0) ;
P = source(file) ;
P = module(apply_macros) ;
P = load_context(nb_set, '/Users/pmoura/lib/swipl/library/nb_set.pl':45, [imports([])]) ;
P = load_count(1) ;
P = number_of_clauses(52).
?- source_file_property('/Users/pmoura/lib/swipl/library/nb_set.pl', P).
P = modified(1547476368.0) ;
P = source(file) ;
P = module(nb_set) ;
P = load_context(solution_sequences, '/Users/pmoura/lib/swipl/library/solution_sequences.pl':46, []) ;
P = load_count(1) ;
P = number_of_clauses(13).
?- source_file_property('/Users/pmoura/lib/swipl/library/solution_sequences.pl', P).
P = modified(1574086719.0) ;
P = source(file) ;
P = module(solution_sequences) ;
P = load_context(editline, '/Users/pmoura/lib/swipl/library/editline.pl':59, []) ;
P = load_count(1) ;
P = number_of_clauses(49).
提供默认方便的命令行历史记录和其他服务。但是,如果您通过在editline.pl
文件中添加以下指令来切换至readline
,则指令:
~/.config/swi-prolog/init.pl
然后您得到:
:- set_prolog_flag(readline, readline).
这是一个较差的解决方法,但可能会对您有所帮助。