给出代码a2.pl:
%% prolog (swipl) command line arguments
%% swipl -s a2.pl -t a --quiet -- "b" "c" "D"
%% which outputs to screen: ['D']
writeln1(Term) :-
term_to_atom(Term,Atom),
writeln(Atom),!.
a:-
current_prolog_flag(argv, AllArgs),
AllArgs=[_,_ | Args],
writeln1(Args),halt.
如何进行查询swipl -s a2.pl -t a --quiet "b" "c" "[[v,b],":-",[[[n,=]]]]"
返回
['[[v,b],:-,[[[n,=]]]]']
返回
[[v,b],":-",[[[n,=]]]]
?
答案 0 :(得分:2)
我发现可以使用以下方法处理术语,将其转换为列表,调用a2.pl为谓词,然后将其转换回术语。
%% term_to_atom([[v,b],":-",[[[n,=]]]],B).
%% B = '[[v,b],":-",[[[n,=]]]]'.
%% ?- string_atom(A,'[[v,b],":-",[[[n,=]]]]').
%% A = "[[v,b],\":-\",[[[n,=]]]]".
%% swipl -s a2.pl -t a --quiet "b" "c" "[[v,b],\":-\",[[[n,=]]]]"
%% ['[[v,b],":-",[[[n,=]]]]']
%% ?- term_to_atom(A,'[[v,b],":-",[[[n,=]]]]').
%% A = [[v, b], ":-", [[[n, =]]]].