0

I need to compile Prolog code into an executable that reads two parameters (one a text string and the other a number)

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

Using the Ciao interpreter I get:

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

But running the same code when compiled using ciaoc give the following error:

~ $ ciaoc test.pl
~ $ ./test hi 5
{ERROR: No handle found for thrown error error(type_error(evaluable,5),arithmetic:is/2-2)}
Dima Chubarov
  • 16,199
  • 6
  • 40
  • 76
CliffN
  • 16
  • 6

1 Answers1

0

The solution I've found is to convert the number into an ascii code and back to a number:

%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.

The compiled executable no longer generates an error:

~ $ ciaoc test.pl
~ $ ./test hi 5
hi
10
CliffN
  • 16
  • 6