Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SWI-Prolog: splitting text atom into list of characters

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?

like image 381
EmmetOT Avatar asked Jan 21 '26 15:01

EmmetOT


1 Answers

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].
like image 93
BretC Avatar answered Jan 23 '26 05:01

BretC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!