我在此Prolog Code行10单词上有一个错误,首先我无法弄清楚我的错误

发布于 2025-01-31 04:34:38 字数 653 浏览 2 评论 0原文


go:- 
    university(area),
    write('Shall we start?: '),
    write(area),
    nl,
    undo.
    
university(csandse) :- csandse, !.
    
csandse :-
    verify(labs),
    verify(classrooms),
    verify(Teachers Staffroom),
    verify(Department's faculty office).
    
ask(Question):-
    write('which area of department you want to visit?: '),
    write(Question),
    write('? '),
    read(Response),
    nl,
    ( (Response == yes; Response == y)
    
    assert(yes(Question));
    assert(no(Question)), fail).
    
:- dynamic yes/1, no/1.
    
verify(S) :-
    (yes(S)
    true ;
    (no(S)
    
    fail ;
    ask(S))).

go:- 
    university(area),
    write('Shall we start?: '),
    write(area),
    nl,
    undo.
    
university(csandse) :- csandse, !.
    
csandse :-
    verify(labs),
    verify(classrooms),
    verify(Teachers Staffroom),
    verify(Department's faculty office).
    
ask(Question):-
    write('which area of department you want to visit?: '),
    write(Question),
    write('? '),
    read(Response),
    nl,
    ( (Response == yes; Response == y)
    
    assert(yes(Question));
    assert(no(Question)), fail).
    
:- dynamic yes/1, no/1.
    
verify(S) :-
    (yes(S)
    true ;
    (no(S)
    
    fail ;
    ask(S))).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坏尐絯℡ 2025-02-07 04:34:38

我已经编辑了该问题以添加代码格式;我们可以看到部门教师办公室中途的颜色变化:

swish 中。正如@brebs的评论,从资本开头的东西是变量,必须用单个引号包裹才能是原子。被用作撇号的引号的人需要使撇号逃脱出来:

verify('Department\'s faculty office')

I've edited the question to add code formatting; we can see the colour changes midway through Department's faculty office:

Screenshot of code

because the apostrophe is throwing it off. The same colour change happens in SWISH. As @brebs comments, things starting with a capital are Variables and must be wrapped in single quotes to be atoms. Ones with quotes used as apostrophes need to have the apostrophe escaped with a backslash:

verify('Department\'s faculty office')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文