Prolog类型不兼容(Prolog type is incompatible)

编程入门 行业动态 更新时间:2024-10-26 12:27:26
Prolog类型不兼容(Prolog type is incompatible)

Visual Prolog 8抛出错误c504:表达式具有类型'() - > :: char procedure',它与类型':: 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).

怎么解决呢?

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?

最满意答案

你似乎有错误:

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

你应该这样写

        C = readChar(), 

在手册中搜索readChar时,可以看到建议的用法

_ = console :: readChar()。

似乎错误消息暗示相同: readChar “是类型() -> char 。” ,而不是“一个char ” 。 你的C是个char 。 要从过程中获取结果,我们通常需要运行它(此“运行”与在代码中run无关)。

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

更多推荐

本文发布于:2023-07-27 05:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1285469.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不兼容   类型   Prolog   type   incompatible

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!