shithub: pprolog

Download patch

ref: d4fc86d5988dacfca455cac55aae71ad4fd3bb95
parent: 9fd0e7fc78740ec3a0a1a5e97d571d0f9d02b85a
author: Peter Mikkelsen <peter@pmikkelsen.com>
date: Tue Jul 13 15:58:03 EDT 2021

Add atom_concat/3

--- a/stdlib.pl
+++ b/stdlib.pl
@@ -230,6 +230,10 @@
 
 % type assertions (throws an error if false)
 
+is_atom(T) :- atom(T), ! ; type_error(atom, T).
+
+is_atom_or_var(T) :- (atom(T) ; var(T)), ! ; type_error(atom, T).
+
 is_callable(T) :- callable(T), ! ; type_error(callable, T).
 
 is_nonvar(T) :- nonvar(T), ! ; instantiation_error.
@@ -376,4 +380,29 @@
 	!,
 	append(Lefts, [A|Rights], Ls1),
 	sort(Ls1, Ls).
-sort(Ls, Ls).
\ No newline at end of file
+sort(Ls, Ls).
+
+% Atomic term processing
+
+atom_concat(A1, A2, A3) :-
+	is_atom_or_var(A1),
+	is_atom_or_var(A2),
+	is_atom_or_var(A3),
+	atom(A1), atom(A2),
+	!,
+	atom_codes(A1, Codes1),
+	atom_codes(A2, Codes2),
+	append(Codes1, Codes2, Codes),
+	atom_codes(A3, Codes).
+atom_concat(A1, A2, A3) :-
+	is_atom_or_var(A1),
+	is_atom_or_var(A2),
+	is_atom_or_var(A3),
+	atom(A3),
+	!,
+	atom_codes(A3, Codes),
+	append(Codes1, Codes2, Codes),
+	atom_codes(A1, Codes1),
+	atom_codes(A2, Codes2).
+atom_concat(A1, A2, A3) :-
+	instantiation_error.
\ No newline at end of file