【问题标题】:How can I include double quotes in a SWI-PL command line argument?如何在 SWI-PL 命令行参数中包含双引号?
【发布时间】:2020-02-22 12:50:49
【问题描述】:

给定代码 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】:

    我发现下面的方法可以用来处理词条,将其转换为列表,调用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, =]]]].
    

    【讨论】:

    • 我将添加一种方法来保存并从文件中读取 a2.pl 的输出,以便在接下来的几天内执行最后一次转换回一个术语。我不想使用 shell 的输出,因为我将使用 SWI-PL 算法的想法,该算法使用复杂的结构,如果不将其打印到文件并中止,我就无法从中获取输出,这会给出失败退出值,阻止它在 shell 中返回输出。相反,我会在 shell 命令失败后写入文件并访问它。
    • 我停止使用 shell 和 file 命令的算法,因为我认为它太复杂了。
    猜你喜欢
    • 2020-07-25
    • 1970-01-01
    • 2011-05-17
    • 1970-01-01
    • 2018-03-19
    • 2017-01-15
    • 2011-10-06
    • 2023-03-19
    相关资源
    最近更新 更多