Basic List Operations in Prolog
Автор: Virgilio Armando Cerna Choto
Загружено: Dec 25, 2024
Просмотров: 6,622 views
Basic List Operations
Here are some common operations you can perform with lists in Prolog:
Checking Membership
To check if an element is a member of a list, you can use the built-in predicate member/2.
% Check if an element is in the list
?- member(apple, [banana, apple, cherry]).
% true
Concatenating Lists
You can concatenate two lists using the append/3 predicate.
% Concatenate two lists
?- append([1, 2, 3], [4, 5], Result).
% Result = [1, 2, 3, 4, 5]
Finding List Length
The length of a list can be determined using the length/2 predicate.
% Find the length of a list
?- length([apple, banana, cherry], Length).
% Length = 3
Reversing a List
To reverse a list, you can use the reverse/2 predicate.
% Reverse a list
?- reverse([1, 2, 3], Reversed).
% Reversed = [3, 2, 1]

Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: