0% found this document useful (0 votes)
27 views9 pages

Prologppt

This document provides an overview of lists in Prolog. It defines what a list is, how it is represented, and common operations on lists like printing, determining length, creating, and searching. It also gives a brief overview of the structure of Prolog programs, including domains, predicates, clauses, and goals. Key list concepts covered include using '.' and '|' to represent and decompose lists, that elements must be of the same type, and how to declare and work with lists in Prolog.

Uploaded by

Nicris
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views9 pages

Prologppt

This document provides an overview of lists in Prolog. It defines what a list is, how it is represented, and common operations on lists like printing, determining length, creating, and searching. It also gives a brief overview of the structure of Prolog programs, including domains, predicates, clauses, and goals. Key list concepts covered include using '.' and '|' to represent and decompose lists, that elements must be of the same type, and how to declare and work with lists in Prolog.

Uploaded by

Nicris
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

PROLOG : LIST

LIST
 Basic data structure
 Eg: [1,2,3] [x,y,z,ffff]
 Object in a list can be anything, including another list.

 All elements of a list must be of same domain.

 Use vertical bar (|) to separate head and tail of a list. [H|
T]
 Head is always the first element.

 Remaining part is a Tail.

 Null [] is also an list.


 “.“ is a functor of arity 2 which is used to represent a list.
 .(a,[]) is a list of length 1 equivalent to [a]

 .(a,.(b,.(c,.(d,[])))) is a list of length 4 equivalent to


[a,b,c,d]
 Declaring a list in prolog :
 Eg : L=symbol*
 L=int* int=integer
PRINTING OUT A LIST
domains
L=symbol*
Predicates
write_list(L).
Clauses
write_list([]).
write_list([H|T]) :-
write(H), nl, write_list(T).
Goal
write_list([a1,a6,a3,abc]).
LENGTH OF A LIST
domains
list = string*
L = integer
predicates
length(list,L)
clauses
length([ ], 0).
length([H | T], N):-
length(T, N1),
N = N1 + 1.
CREATING A LIST
domains
create_list = string*
predicates
input_data(create_list)
clauses
input_data ([H | T]):-
write(“Input data (#: to end):”),
readln(H),
H <> “#”, !
input_data (T).
input_data ([ ]).
goal
input_data(L).
SEARCHING IN A LIST
domains
namelist = name*
name = symbol 
predicates
member (name, namelist)
Clauses
member(N,[]):- write(false).
member (N, [ N| _ ] ).
member (N,[_ |Tail]) :-
member (N,Tail).
• Same Length :
slength([],[]).
slenght([X | Restof1], [Y | Restof2]) :-
slength(Restof1, Restof2).
PROLOG OVERVIEW
 Structure :
 Domain – Variable declaration could be made.
 Types : Symbol, Char, integer, real, string, file
 Predicate – like Function declaration.
 Clause – consists of facts and rules.(procedure)
 Goal – Like a main function in C program

 ‘,’ represents “AND”


 ‘;’ represents “OR”

 Terms :
 Constant – Names an individual
 Variable – Stands for an individual unable to be named when the
program is written
 Compound term – Names of an individual that have parts

You might also like