将数字作为参数传递给可执行文件(使用 ciaoc 编译的 Prolog 代码)会产生错误

Passing a number as a parameter to an executable (Prolog code compiled using ciaoc) generates an error

我需要将 Prolog 代码编译成可读取两个参数(一个是文本字符串,另一个是数字)的可执行文件

%test.pl:
main([A,N]) :-
            Z is 2 * N,
            write(A), nl,
            write(Z), nl.

使用 Ciao 解释器我得到:

?- main([hi,5]).
hi
10

但是 运行 使用 ciaoc 编译相同的代码时会出现以下错误:

~ $ ciaoc test.pl
~ $ ./test hi 5
{ERROR: No handle found for thrown error error(type_error(evaluable,5),arithmetic:is/2-2)}

我找到的解决方案是将数字转换为 ascii 码,然后再转换回数字:

%test.pl
main([A,N]) :-
        atom_codes(N, Code), % find ascii code for N
        number_codes(X, Code), % find number from ascii code
        Z is 2 * X,
        write(A), nl,
        write(Z), nl.

编译后的可执行文件不再产生错误:

~ $ ciaoc test.pl
~ $ ./test hi 5
hi
10