我如何在SWI-PL命令行参数中包含双引号?

问题描述 投票:0回答:1

给出代码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,=]]]]

arguments command line quotes swi-prolog
1个回答
0
投票

[我发现以下方法可用于处理术语,将其转换为列表,调用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, =]]]].
© www.soinside.com 2019 - 2024. All rights reserved.