简体   繁体   English

Prolog:要列出的字符串

[英]Prolog: String to List

I have a string that I want to convert to a list: 我有一个想要转换为列表的字符串:

"a + b = c"

I need it in list format to pass it onto to a member rule. 我需要以列表格式将其传递给成员规则。 When I pass it onto the member rule directly, it passes as a series of numbers which I assume is their character code, but I want the actual characters instead. 当我直接将其传递给成员规则时,它将作为一系列数字传递,我认为这是它们的字符代码,但我需要实际的字符。 How do I make it into a list then use it with a rule. 如何将其放入列表,然后将其与规则配合使用。 I'm a novice in Prolog so I would appreciate any help. 我是Prolog的新手,所以我将不胜感激。

SWI-Prolog has string_chars/2, but you can obtain the same using 2 ISO conforming predicates SWI-Prolog具有string_chars / 2,但是您可以使用2个符合ISO的谓词来获得相同的结果

?- atom_codes(A, "a + b = c"), atom_chars(A, Cs).
A = 'a + b = c',
Cs = [a, ' ', +, ' ', b, ' ', =, ' ', c].

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM