Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I call the predicate split_string on swi-prolog?

Tags:

swi-prolog

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?

like image 853
svelten Avatar asked Jun 13 '14 18:06

svelten


1 Answers

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.

like image 166
false Avatar answered Oct 01 '22 11:10

false