Search code examples
prolog

How to concatenate two atoms/strings?


I'm trying to find out how to concatenate two atoms:

A = 'my ', 
B = 'atom',

How can I concatenate these two atoms so that the result is:

'my atom'

?


Solution

  • For atoms:

    ?- atom_concat('my ', 'atom', X).
    X = 'my atom'.
    

    For strings:

    :- set_prolog_flag(double_quotes, chars).
    :- use_module(library(double_quotes)).
    
    ?- append("my ", "string", X).
    X = "my string".
    

    It took me a while to find the proper names. Maybe it will help others too.