Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to concatenate two atoms/strings?

Tags:

prolog

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' 

?

like image 677
Martin Vseticka Avatar asked Jun 03 '13 13:06

Martin Vseticka


People also ask

How do you join two strings together?

Concatenation is the process of appending one string to the end of another string. You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs.

What does concatenate two strings mean?

Use CONCATENATE, one of the text functions, to join two or more text strings into one string.

How do you concatenate in Prolog?

It can be done by using append. concatenate(List1, List2, Result):- append(List1, List2, Result). Hope this helps. Save this answer.


1 Answers

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.

like image 119
Martin Vseticka Avatar answered Sep 30 '22 03:09

Martin Vseticka