0

I'm a little bit confused. I would like to use the split_string function which can be seen here. But I just don't know how to import or use this function. Do I have this pl File already on my PC? I can only find strings.pl in C:\Program Files\swipl\library\dialect\ciao but I doesn't include the split_string function.

I'm pretty sure it's totally easy but I just can't figure it out.

Thanks!

Tim
  • 193
  • 4
  • 15

1 Answers1

3

You will probably need to install the "development release" of SWI-Prolog (major version 7), if you haven't yet. On Windows and MacOS, this simply means getting the right binaries. For Linux, you can either add the PPA (on the same page), or build from source, which is straight-forward enough.

Then, you will get something along the lines of: (note the banner with the version number)

$ swipl
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.1.25)
Copyright (c) 1990-2014 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?- split_string("a.b.c", ".", "", L).
L = ["a", "b", "c"].

You shouldn't need to import anything explicitly.

Does that solve your problem?

  • I encountered a problem a problem with SWI7 and had to return to SWI6. Is there are possibility to use something like split string in SWI6? – Tim Oct 22 '14 at 12:12
  • @Tim you get a lot of overlapping functionality between strings and atoms. But there is really no reason to stick to SWI6, if you are going to be using SWI-Prolog. –  Oct 22 '14 at 13:01
  • Thanks, I found out that **atomic_list_concat** does what i need. I have to stick with SWI6 because of the problem found here: http://www.complang.tuwien.ac.at/ulrich/iso-prolog/SWI7_and_ISO – Tim Oct 22 '14 at 13:07
  • @Tim This is not a problem, really. This page lists a bunch of corner cases in which SWI-Prolog departs from strict ISO-Prolog compliance. This is a far cry from making the implementation "broken", it is simply different for some convoluted examples. There are many other issues with SWI6, too, in regards to ISO-compliance. My point was, for "learning", yes, stick to SWI6. For real-world developments, move on to SWI7 or pick another implementation. –  Oct 22 '14 at 13:10
  • @Tim I cannot agree that the examples where SWI differs are all convoluted. Take `writeq('.'(3,[])).` which is canonical syntax in ISO Prolog, that is, it can be read regardless of the current operator declarations, but SWI7 rejects this. That means: It is impossible to reliably recover "serialized" Prolog terms in SWI. The situation is even worse: SWI7 cannot reliably read its own terms back (in the presence of strings). Since SWI7 uses a lot of strings by default, this means that there is no longer a reliable way to store data in a non-proprietary way. This makes SWI7 seriously broken. – false Jan 02 '15 at 19:57