Search code examples
prologvisual-prolog

Prolog type is incompatible


Visual Prolog 8 throws error c504 : The expression has type '() -> ::char procedure', which is incompatible with the type '::char'.

main.pro

implement main
    open core, console

class predicates
    цикл : ().
    print : ().

clauses
    цикл().

    print() :-
        console::initUtf8(),
        цикл,
        C = readChar,
        /* Читать символ и связывать его с переменной  C */
        write(C),
        C1 = convert(char, C),
        C2 = convert(char, '\r').
        C1 = C2.
        /* Является ли введенный символ возвратом каретки? fail, если нет */

    run() :-
        цикл,
        fail.

    run() :-
        succeed.
        % place your own code here

end implement main

goal
    mainExe::run(main::run).

How can to fix it?


Solution

  • You seem to have the error here:

        print() :-
            ....
            цикл,
            C = readChar,       % <<-------
    

    You should write it like this

            C = readChar(),

    as searching for readChar in the manual reveals, where one can see the suggested usage as

    _ = console::readChar().

    Seem that the error message suggests the same: readChar "is a procedure of type () -> char.", not "a char". Your C is a char. To get the result from a procedure we usually need to run it (this "run" is unrelated to run in your code).