Search code examples
stringprolog

How to know if an atom is starting with a pattern?


For example, if I got the following predicates :

father('jim', 'Boby')
father('rob', 'bob') 

and I would like to know who got father with is name starting with 'bo' ?


Solution

  • Another ISO option is sub_atom/5:

    sub_atom(Atom, Before, Length, After, Sub_atom)

    ?- sub_atom(bob, 0, _, _, bo).
       true.
    

    Compared to atom_concat/3, this avoids the generation of the unneeded atom to represent the suffix.