-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstrings_equal.pl
More file actions
26 lines (21 loc) · 2.03 KB
/
strings_equal.pl
File metadata and controls
26 lines (21 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
% ***************************************************************************************************
% Predicate to Check if Two Strings are Equal *
% *
% This Prolog code defines a predicate to check if two strings are equal by comparing their *
% constituent characters. *
% *
% - `strings_equal/2`: Predicate to check equality of two strings. *
% *
% Example usage: *
% ?- strings_equal("hello", "hello"). *
% true. *
% ?- strings_equal("hello", "world"). *
% false. *
% *
% ***************************************************************************************************
% ---------------------------------- Predicate to check if two strings are equal ----------------------------------
% Check if two strings are equal by comparing their character lists
strings_equal(String1, String2) :-
string_chars(String1, Chars1), % Convert String1 to a list of characters
string_chars(String2, Chars2), % Convert String2 to a list of characters
Chars1 = Chars2. % Unify the character lists to check equality