我可以在 Prolog 中将字符列表转换为字符串或术语吗

发布于 2024-10-10 04:10:51 字数 225 浏览 0 评论 0原文

read_line_to_codes(Stream,Line)

首先从文件中读取一行.. 有没有办法读取一行并将其分配给序言中的一个术语?如果不是,我设法读取一行并将其放入此字符列表中..现在此字符列表包含空格..这很糟糕..所以我想将其转换为序言中的术语或字符串,以便我可以处理它更容易..空间不能是原子,所以这是一个问题..

我感谢您的帮助!

i use

read_line_to_codes(Stream,Line)

to read a line from a file .. first
is there any way to read a line and assign it to a term in prolog ?? if not i managed to read a line and put it in this char list .. now this char list contains spaces .. which is bad .. so i want to convert it to a term or a string in prolog so that i can process it easier .. spaces cannot be atoms so thats a problem ..

i appreciate the help !!

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

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

发布评论

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

评论(1

北渚 2024-10-17 04:10:51

如果您的输入包含 Prolog 术语,请使用 read/1。您可以使用atom_codes/2 将字符代码转换为原子。空格“ ”也是一个原子,您可以通过查询看到:?-atom(' ')。使用 SWI-Prolog 从文件读取其他输入的一个好方法是使用 DCG 对其进行描述,然后使用库 (pio) 中的phrase_from_file/2。

If your input consists of Prolog terms, use read/1. You can convert character codes to an atom with atom_codes/2. A space, ' ', is also an atom, you can see that with the query: ?- atom(' '). A good way to read other input from a file with SWI-Prolog is to describe it with a DCG and then to use phrase_from_file/2 from library(pio).

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