SWI-Prolog: splitting text atom into list of characters

♀尐吖头ヾ 提交于 2019-12-20 03:00:35

问题


Very simple question: I know there are plenty of ways to split an atom, eg 'example atom' on some delimiter, eg ' ' -> ['example', 'atom'] but is there a way to split up every character? Eg ['e', 'x', 'a', ... 'o', 'm']. I've tried

atomic_list_concat(List, '', Atom),

but that generates the error

ERROR: atomic_list_concat/3: Domain error: `non_empty_atom' expected, found `'

What would you recommend?


回答1:


Do you want something like this?

http://www.swi-prolog.org/pldoc/doc_for?object=atom_chars/2

?- atom_chars(hello, X).
X = [h, e, l, l, o].


来源:https://stackoverflow.com/questions/31478457/swi-prolog-splitting-text-atom-into-list-of-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!