-


- - . 14


Str1_2 = Char U Str2
3.frontstr(Length,InpString,StartString,RestString) -
Length InpString StartString, - RestString.
4.fronttoken(String,Token,RestString)
String - ;
Token - ( );
RestString - .
5.str_len(String,Length) - .
8. .
domains
charlist=char*
predicates
name(string,charlist)
clauses
name(" ",[]).
name(S,[H|T]):-frontchar(S,H,S1), name(S1,T).
9. .
domains
namelist=name*
name=symbol
predicates
string_namelist(string,namelist)
clauses
string_namelist(S,[H|T]):-fronttoken(S,H,S1),!,string_namelist(S1,T).
string_namelist(_,[]).
3.5. findall
 
findall(X,P,L) L X, P.
10.
domains
name, address = string
age = integer
list = age*
predicates
person(name, address, age)
sumlist(list, age, integer)
goal
findall(Age, person(_, _, Age), L), sumlist(L, Sum, N), Ave = Sum/N, write("Average =", Ave), nl.
clauses
sumlist([], 0, 0).
sumlist([H|T], Sum, N) :- sumlist(T, S1, N1), Sum=H+S1, N=1+N1.
person("Sherlock Holmes", "22B Baker Street", 42).
person("Pete Spiers", "Apt. 22, 21st Street", 36).
person("Mary Darrow", "Suite 2, Omega Home", 51).
3.6.
1. f g. h f, g .



- -  - -  - -