I am trying following code, where foreach and string_codes are working separately:
7 ?- string_codes("acid", D).
D = [97, 99, 105, 100].
8 ?- string_codes(S, [116, 101, 115, 116]).
S = "test".
15 ?- foreach(member(S, ["test", "acid"]), writeln(S) ).
test
acid
true.
But not together:
14 ?- foreach(member(S, ["test", "acid"]), string_codes(S, X) ).
false.
17 ?- foreach(member(X,[[116, 101, 115, 116], [97, 99, 105, 100]]), string_codes(S, X)).
false.
Only first letter is printed with this code:
77 ?- foreach(member(X, [[97], [98],[99]]), (string_codes(S,X), writeln(S))).
a
Where is the problem and how can it be solved?
Edit: maplist works only one way:
74 ?- maplist(string_codes, ["test","acid"], L).
L = [[116, 101, 115, 116], [97, 99, 105, 100]].
73 ?- maplist(string_codes, L, [97, 98,99]).
ERROR: string_codes/2: Type error: `list' expected, found `97' (an integer)
Actually, each number should be a list:
75 ?- maplist(string_codes, L, [[97], [98],[99]]).
L = ["a", "b", "c"].
How can I convert a list of numbers into a list of lists?
I am trying:
tolistlist([H|T],[[H]|Outl]):-
writeln([[H]]),
tolistlist(T,Outl).
tolistlist([],[]).
It does produce list of numbers in that pattern but still does not work:
[[115],[116]]
ERROR: string_codes/2: Type error: `character_code' expected, found `[116]' (a list)
105 ?-