Prolog程式語言

1.The interpreter in Figure 23.6 is inefficient. Generate clauses like: Area(square(Slide),Area) :- Area is Slide * Slide. Area(rectangle(Length, Width),Area) :- Area is Length * Width. 2.Use the program HYPER in Figure 19.7 to generate concatenation program below:< ... 顯示更多 1.The interpreter in Figure 23.6 is inefficient. Generate clauses like:
Area(square(Slide),Area) :- Area is Slide * Slide.
Area(rectangle(Length, Width),Area) :- Area is Length * Width.

2.Use the program HYPER in Figure 19.7 to generate concatenation program below:<
conc([], L, L).
conc([X|L1],L2,[Y|L3]) :- conc(L1,L2,L3).

3.Rewrite a semantic network similar to Figure 15.14. The following clauses represent a square s1 and a rectangle r1 and specify the method for computing the area of a figure:
s1(instance_of, square).
s1(side, 5).
r2(instance_of, rectangle).
r2(length, 6).
r2(width, 4).

square(a_kind_of, rectangle).
square(length, execute(value( Obj, Slide, L)), Obj, L).
square(width, execute(value( Obj, Slide, W)), Obj, W).

rectangle (area, execute(area(Obj, A)), Obj, A).

area( Obj, A) :- value(Obj, length, L), value(Obj, width, W), A is L * W.

% ?- value(r2,length,A), value(s1,width,B), value(s1,area,C).
1 個解答 1