Tuesday, 26 August 2014

Prolog program to find the last element of the list

Prolog program to find the last element of the list

Program:

domains
    list=symbol*
    
predicates
    last(list)

clauses
    last([X]):- write("\nLast element is :" ,X).
    last([Y|Tail]):-last(Tail).
    

goal with output

goal: replace([a,b,c,d,a,b]).
output: Last element is :gTrue


Back | List Programs | Next