Atom_split/3 is not defined?

I’m using: SWI-Prolog version 8.0.2.

When I try to use atom_split/3 I get the following error:

5 ?- atom_split(big_dog_tom, '_', X).
ERROR: Undefined procedure: atom_split/3 (DWIM could not correct goal)

I don’t see a library reference on the docs page:

https://www.swi-prolog.org/pldoc/doc_for?object=ifprolog%3Aatom_split/3

Where can I find this useful predicate?

1 Like

atom_split/3 is in a compatibility package as you note and is probably not what you really want.

However in standard SWI-Prolog is

atomic_list_conca(+List, +Separator, -Atom)

Creates an atom just like atomic_list_concat/2, but inserts Separator between each pair of inputs. For example:

?- atomic_list_concat([gnu, gnat], ', ', A). 
A = 'gnu, gnat'

The SWI-Prolog version of this predicate can also be used to split atoms by instantiating Separator and Atom as shown below.

?- atomic_list_concat(L, -, 'gnu-gnat').
L = [gnu, gnat]

In your case:

?- atomic_list_concat(L,'_',big_dog_tom).
L = [big, dog, tom].

For others reading this, _ is a variable and can cause problems here while '_' is an atom e.g.

?- atomic_list_concat(L,_,big_dog_tom).
ERROR: Arguments are not sufficiently instantiated
ERROR: In:
ERROR:    [8] atomic_list_concat(_7338,_7340,big_dog_tom)
ERROR:    [7] <user>
1 Like

Do you have a similar replacement for at_split/3?:

https://www.swi-prolog.org/pldoc/doc_for?object=hprolog%3Asplit_at/4

See source

1 Like

See: pakage list_util (docs)

Also see: Package install errors - How to resolve after SWI-Prolog changed to using HTTPS

example:

?- list_util:split_at(2,[a,b,c,d,e],Prefix,Suffix).
Prefix = [a, b],
Suffix = [c, d, e].
1 Like

You don’t need github for that :slight_smile:

21 ?- listing( atomic_list_concat/3).
%   Foreign: system:atomic_list_concat/3

true.

22 ?- use_module(library(dialect/ifprolog)).
true.

23 ?- listing(atom_split/3).
ifprolog:atom_split(Atom, Delimiter, Subatoms) :-
    atomic_list_concat(Subatoms, Delimiter, Atom).

true.

Getting O(n^2) is not needed if you use a code list as intermediate. You might need a high N to win using code lists though.