Use of split_string in SWI Prolog

597 Views Asked by At

On executing the following query in prolog :-

split_string("/usr/local/eclipse", "/", "", [H|T]), split_string(T, "", "", X), write(X)

The error is

ERROR: split_string/4: Type error: `character_code' expected, found `"usr"' (a string)

I am not able to resolve it. Please help!.

1

There are 1 best solutions below

0
On

String variable in split_string(+String, +SepChars, +PadChars, -SubStrings) is intended to containt list of charcodes. In your example

split_string("/usr/local/eclipse", "/", "", [H|T]).
H = "",
T = ["usr", "local", "eclipse"].

So T is a list of lists of charcodes. That's why there is an error in the next part of your query:

split_string(T, "", "", X), write(X)

I don't know what your code is intended to do, so I can't propose a way to fix your code.