%% Top-Down Execution of Programs % Schema %------- database({part(Number:integer, Shape:any, Weight:any)}). %A DB of flat parts described by their geometric shape and weight. %Different geometric shapes require a different number of %parameters. Also actualkg is the actual weight of the %part, but unitkg is the specific weight where the actual %weight can be easily derived from the area of the part part_weight(No, Kilos) <- part(No, _, actualkg(Kilos)). part_weight(No, Kilos) <- part(No, Shape, unitkg(K)), area(Shape, A), Kilos = K * A. % functor area(circle(Dmtr), A1) <- A1 = Dmtr * Dmtr * 3.14/4. area(rectangle(Base, Height), A1) <- A1 = Base*Height. export part_weight(X, Y). % we may also reversely derive unitkg from actualkg and area unit_weight(No, Kilos) <- part(No, Shape, actualkg(K)), area(Shape, A), Kilos = K / A. export unit_weight(X, Y).