Prolog:未捕获的异常:错误(syntax_error('user_input:4(char:7)

时间:2017-05-28 19:16:20

标签: 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)

这是我的序言。

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.

0 个答案:

没有答案