prolog - 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
解决方案
从 swipl --traditional 开始将解决这个问题,但是还有很长的路要走,您还可以设置与双引号相关的 prolog 选项
这个问题很老了,我想知道你是否设法完成了构建和训练
推荐阅读
- git - git pull origin master 没有按预期工作
- php - 如何从foreach中的两个数组中获取对应的键值
- python - 如何使用 .bat 文件每 5 分钟关闭并重新运行 python exe
- java - 我怎样才能重复一个模式?
- scala - spark(with scala)中reduceByKey的意外行为?spark或scala中的“rev”保留字?
- python - 当在 OptionMenu 上选择一个选项并按下一个按钮然后为该特定选项发生某些事情时,我该如何做到这一点
- php - 为什么即使 php 版本正确,我也不能在 ssh 上运行 composer install?
- image - 如何在 Flutter 中使用带有 CachedNetworkImage 的视差效果?
- amazon-web-services - AWS S3:如果我们在 S3 存储桶中获得大于 10 MB 的对象,则需要发送通知
- php - 新的 mongoDB PHP 驱动程序:使用 Limit 和 Skip 以及 multipal OR 条件查询不同的记录