Functional programming 序言:未捕获异常:错误(语法错误(';用户输入:4(字符:7)

Functional programming 序言:未捕获异常:错误(语法错误(';用户输入:4(字符:7),functional-programming,prolog,logic,Functional Programming,Prolog,Logic,当我尝试运行Prolog代码时,我收到以下错误消息。我对这种语言非常陌生,在查找错误时遇到很多困难。我正在使用GNU Prolog编译器。(Daniel Diaz的1.4.4版)我相信错误与列表或成员谓词有关。你能帮我吗 uncaught exception: error(syntax_error('user_input:4 (char:7) expression expected'),read_term/3) 这是我的prolog代码 alien(flubsub). alien(gribbe

当我尝试运行Prolog代码时,我收到以下错误消息。我对这种语言非常陌生,在查找错误时遇到很多困难。我正在使用GNU Prolog编译器。(Daniel Diaz的1.4.4版)我相信错误与列表或成员谓词有关。你能帮我吗

uncaught exception: error(syntax_error('user_input:4 (char:7) expression expected'),read_term/3)
这是我的prolog代码

alien(flubsub).
alien(gribbet).
alien(jarix).
alien(wattin).

child(andrew).
child(dudley).
child(georgina).
child(karen).

features(bubbles).
features(colors).
features(eyes).
features(fins).

solve :-
    alien(andrewAlien), alien(dudleyAlien), alien(georginaAlien),alien(karenAlien),

    all_different([andrewAlien, dudleyAlien, georginaAlien, karenAlien]), 

    feature(andrewFeature), feature(dudleyFeature), feature(georginaFeature), feature(karenFeature),

    all_different([andrewFeature, dudleyFeature,georginaFeature,karenFeature]),

    Owners = [ [andrew,andrewAlien,andrewFeature],
        [dudley,dudleyAlien,dudleyFeature],
        [georgina,georginaAlien,georginaFeature],
        [karen,karenAlien,karenFeature]
                     ],

    % 1. Dudley didn't walk out of the store with either Flubsub or Jarix, and his alien doesn't develop fins when placed in water. 
    \+ member([dudley,flubsub,_],Owners),
    \+ member([dudley,jarix,_],Owners),
    \+ member([dudley,_,fins],Owners),


    %2. Jarix (which isn't the name of the alien Andrew picked) has eyes that glow in the dark.

    \+ member([andrew,jarix,eyes],Owners),
     member([_,jarix,eyes],Owners),

    %3 Karen left the toy store with the alien Wattin
    member([karen,wattin,_],Owners),


    %4 Andrew doesn't own the alien that develops fins and Dudley doesn't own the alien that blows bubbles

    \+ member([andrew,_,fins],Owners),
    \+ member([dudley,_,bubbles],Owners),

    tell(andrew,andrewAlien,andrewFeature),
    tell(dudley,dudleyAlien,dudleyFeature),
    tell(georgina,georginaAlien,georginaFeature),
    tell(karen,karenAlien,karenFeature).


    %Succeeds if all elements of the argument list are bound and different
    %Fails if any elements are unbound or equal to some other element

    all_different([H |  T]) :- member(H, T), !, fail.
    all_different([_  |  T]) :- all_different(T).
    all_different([_]).

    tell(x, y, z) :-
        write('  '), write(x), write( ' got the '), write(y),
        write(' with feature '), write(z), write('.'),nl.

你是说编译还是运行?据我所知,Prolog加载你的程序时不会产生错误。我尝试查询
solve
,但失败了,没有错误消息。我是说“运行”。很抱歉,我运行了它,它只是说“false”。没有错误消息。您确定上面显示的代码是您运行的代码吗?我在GNU Prolog上进行了尝试,得到了与使用SWI Prolog相同的结果。查询
solve
给了我“No”(相当于“fail”),但没有错误消息。我使用了
gprolog
版本1.4.4。Prolog不像Pascal或C。你不应该使用括号来表示没有参数。我很确定它会失败,因为
solve
alien(andrewAlien)
。您没有一个事实或规则可以使这项工作成功。您知道Prolog中的变量必须以大写字母开头,或者对于匿名变量必须以
\uu
开头吗?请参阅Prolog文档中的介绍材料。您是指编译还是运行?据我所知,Prolog加载您的程序时不会产生错误。我尝试了查询
solve
,但失败了,没有错误消息。我的意思是“运行”。很抱歉,我运行了它,它只是说“false”。没有错误消息。你确定上面显示的代码就是你运行的代码吗?我在GNU Prolog上尝试了它,得到了与使用SWI Prolog相同的结果。查询
solve
给了我“否”(相当于“fail”),但没有错误消息。我使用了
gprolog
version 1.4.4。Prolog不像Pascal或C。你不应该在没有参数的情况下使用括号。我很确定它失败是因为
solve
alien(andrewAlien)中的第一个查询
。您没有一个事实或规则可以使这项工作成功。您知道Prolog中的变量必须以大写字母开头,或者对于匿名变量,请参见Prolog文档中的介绍材料。