List in Prolog
List in Prolog
List([1, 2, 3, 4]).
Example:
Head = red
Conter example:
L = ([ a | Tail ]).
Result : L = [a,b,c,d,e]
Operations
1. Concatination :
Concat ( [ ] , L , L).
Concat( [X1] | L1 , L2 , [X1 | L3] )
:- Concat ( L1 , L2 , L3) .
2. Membership
ListMember ( X , L )
Where : X : an object
L : is a List
Goal :
Observation:
X is a Member of L if:
Code:
Listmember ( X , [ X | _ ] ).
Listmember ( X , [ _ | Tail] )
Cases:
1. If X is the Head of the list,
Result: The Tail of the List
2. If X is in the Tail,
Then, it is deleted from there
Code:
delete ( Y , [ Y ] , [ ] ).
PS : the delete function it is not working, try to solve it for the next TP