I am trying to use the supposedly built-in predicate split_string/4 from the documentation here: http://www.swi-prolog.org/pldoc/man?predicate=split_string/4
However, when I try to use it, as in the example, I get something like this:
?- split_string("a.b.c.d", ".", "", L).
ERROR: toplevel: Undefined procedure: split_string/4 (DWIM could not correct goal)
What am I doing wrong? Am I supposed to load some library first?
split_string/4
is a SWI specific built-in that has been introduced in SWI7. It is not present in commercial versions of Prolog like SICStus, nor ISO, so using it will reduce your future options to change. Also note that the default interpretation for double quotes is usually codes
, see What is the difference between ' and " in Prolog?
In previous versions of SWI, that is in SWI6 and before, there is concat_atom/3
resp. atomic_list_concat/3
which gives you comparable functionality.
?- atomic_list_concat(L,'_',a_b__c).
L = [a,b,'',c].
Then there are the ISO built-ins: atom_concat/3
and sub_atom/5
which might be used to implement it. So using atomic_list_concat/3
would not pose a big portability problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With