From d4fc86d5988dacfca455cac55aae71ad4fd3bb95 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Tue, 13 Jul 2021 19:58:03 +0000 Subject: Add atom_concat/3 --- stdlib.pl | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'stdlib.pl') diff --git a/stdlib.pl b/stdlib.pl index 803c0ee..96132f0 100644 --- a/stdlib.pl +++ b/stdlib.pl @@ -230,6 +230,10 @@ atomic(T) :- atom(T) ; integer(T) ; float(T). % 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 @@ sort(Ls0, Ls) :- !, 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 -- cgit v1.2.3