.


:




:

































 

 

 

 


Domains. person(name, address, age)




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).

 

 

findall L, , person. 42 ,

Findall(Who, person(Who,_,42), List).

 

 

8.5. .

,

[2,3,5,12,[food,"goo"], "new"]

, . , , , . .

, , , , . , . , :

Domains

llist = l(list); s(symbol); i(integer); c(char); t(string)

list = llist *

:

[i(2),(3),i(5),i(12), [c(food),s(goo)],s(new)]

append :

Domains

llist = l(list); s(symbol); i(integer); c(char); t(string)

list = llist *

Predicates

Append(list, list, list)

 

Goal

makewindow(1,7,7, "answer",15,0,8,80),

/*Note how you can use the same code but need functors *

* append([likes,[bill,mary]],[bill,sue],Ans) */

append([s(likes),l([s(bill),s(mary)])],[s(bill),s(sue)],Ans), */

write("First List:", Ans), nl,nl,

/*The trick is to write the list first, than add the functors *

* append([apple,[[[47], '\1']], [[["This is a string",b,7, *

* 'w']],bee], ['c'], Ans2) */

*

append([l[s("This"), s("is",s("a"),s("list"))]), s(bee)],

[c('c')], Ans2),

write("Second List:", Ans2), nl.

 

Clauses

/* Concatenate two lists */

append([], L, L).

append([X|L1], L2, [X|L3]):- append(L1, L2, L3).

8.6. .

.

' : .

:

Domains

toklist = string*

Predicates

Tokl(string, toklist)





:


: 2015-10-01; !; : 384 |


:

:

- - , .
==> ...

1660 - | 1616 -


© 2015-2024 lektsii.org - -

: 0.01 .