Prolog program for finding the last item of the list in Artificial Intelligence


% Last item of a given list.....

% Alamgir Hossain, CSE, JUST
namelist = symbol*
lastd(namelist,symbol).
lastd([Head],X):-

    X = Head.

lastd([_|Tail],X):-

    lastd(Tail,X).
% End of code
   
% Output---------



%Input :
% :  lastd([a,b,c,d],X).

% output : X = d

No comments:

Post a Comment