I like the answer "pat fats", but you need to convert your string to atom before:
..., atom_codes(Atom, String), atomic_list_concat(L, ' ', Atom), ...
If you need to work directly with strings, I have this code in my "arsenal":
%% split input on Sep % % minimal implementation % splitter(Sep, [Chunk|R]) --> string(Chunk), ( Sep -> !, splitter(Sep, R) ; [], {R = []} ).
being a DCG, should be invoked as follows:
?- phrase(splitter(" ", L), "this is a string"), maplist(atom_codes, As, L). L = [[116, 104, 105, 115], [105, 115], [97], [115, 116, 114, 105, 110|...]], As = [this, is, a, string] .
edit: more explanation
I forgot to explain how this works: DCG is well explained by @larsman, in this other answer. I quote him
-> which actually adds two hidden arguments to it. The first one is a list to be analyzed according to the grammar rule; the second - "what remains" after parsing. c (F, X, []) calls c in the list X to get the result of F, expecting [] to remain on the left, i.e. the parser must consume the entire list of X.
Here I have 2 arguments, the first is a separator, the second is a list under construction. The built-in line // 1 comes from the SWI-Prolog library (http / dcg_basics). This is a very convenient building block that literally matches anything on return. Here he "eats" each char before the delimiter or end of line. By doing this, we can recursively ...