首页 > 解决方案 > Swi-prolog 类型错误:预期为“列表”,找到一个化合物

问题描述

当我尝试使用以下代码连接字符串时输入错误。预期的行为是将字符串的串联生成为FName.

make_file_name(Prefix, Extension, FName) :-
    ( atom(Prefix) ->
          name(Prefix, PrefixStr)
    ; PrefixStr = Prefix
    ),
    ( atom(Extension) ->
          name(Extension, ExtensionStr)
    ; ExtensionStr = Extension
    ),
    append(PrefixStr, ExtensionStr, FNameStr),
    name(FName, FNameStr).

可能会产生如下错误:

➜  chill git:(master) ✗ swipl                                                     [18/06/18| 4:23PM]
Welcome to SWI-Prolog (threaded, 64 bits, version 7.6.4)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit http://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- consult('test_name.pl')
|    .
true.

?- make_file_name('orig-db', "-parser.pl", TestProg).
ERROR: Type error: `list' expected, found `[111,114,105,103,45,100,98|"-parser.pl"]' (a compound)
ERROR: In:
ERROR:    [9] name(_3402,[111,114|...])
ERROR:    [7] <user>
ERROR: 
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.

从错误信息中,很容易猜到字符串orig-db被转换为ASCII列表。

我可以使用 prolog 提供测试yap,这也令人困惑。

➜  chill git:(master) ✗ yap                                                      [18/06/18| 4:03PM]
% Restoring file /usr/lib/Yap/startup.yss
YAP 6.2.2 (x86_64-linux): Sat Sep 17 13:59:03 UTC 2016
   ?- [user].
 % consulting user_input...
| make_file_name(Prefix, Extension, FName) :-
| ( atom(Prefix) ->
|       name(Prefix, PrefixStr)
| ; PrefixStr = Prefix
| ),
| ( atom(Extension) ->
|       name(Extension, ExtensionStr)
| ; ExtensionStr = Extension
| ),
| append(PrefixStr, ExtensionStr, FNameStr),
| name(FName, FNameStr).
| 
 % consulted user_input in module user, 1 msec 9536 bytes
yes
   ?- make_file_name('orig-db', "-parser.pl", TestProg).
no

希望有人能帮忙处理一下这个案子。我是新手prolog,想了解更多。

谢谢!


我正在尝试将较早的代码迁移到由 Raymond J. Mooney ftp://ftp.cs.utexas.edu/pub/mooney/chill/SWI-Prolog或更早编写的 代码。所有带有这个标签的问题都与这个任务有关。我是序言的新手,欢迎提供帮助和建议!SICStus 3 #3: Thu Sep 12 09:54:27 CDT 1996

标签: prologtypeerrorswi-prolog

解决方案


从 swipl --traditional 开始将解决这个问题,但是还有很长的路要走,您还可以设置与双引号相关的 prolog 选项

这个问题很老了,我想知道你是否设法完成了构建和训练


推荐阅读