# 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:<

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 0 年前
最佳解答

回答的prolog問題，最後都被移除，生氣。

本來不想回答；

但是忍不住對prolog的愛，

就回答一題吧！

Area(square(Slide),Area) :- Area is Slide * Slide.

就是

Area(square(Slide),Area) :- Area = Slide * Slide.

.

Area(rectangle(Length, Width),Area) :- Area is Length * Width.

就是

Area(rectangle(Length, Width),Area) :- Area=Length * Width.

簡單吧！

想成函數就可以了。

參考資料： 郁筱平就是我