Object subclass : Amount instanceVariableNames: 'totalCents' classVariableNames: '' !Amount class method! Dollars: d cents: c self new dollars: d cents: c !Amount instance methods! * aValue | newTotalCents | newTotalCents ( totalCents * aValue. ( Amount Dollars: (newTotalCents rem: 100) Cents: (newTotalCents quo: 100) + anAmount | newTotalCents | newTotalCents ( totalCents + anAmount totalCents. ( Amount Dollars: (newTotalCents rem: 100) Cents: (newTotalCents quo: 100) - anAmount | newTotalCents | newTotalCents ( totalCents - anAmount totalCents. ( Amount Dollars: (newTotalCents rem: 100) Cents: (newTotalCents quo: 100) > anAmount ( totalCents > (anAmount totalCents) cents ( totalCents rem: 100 dollars ( totalCents quo: 100 dollars: d cents c: totalCents ( 100 * d + c totalCents ( totalCents
(define (mystery n)
(let ((f1 (lambda (fi) (fi fi 1 1)))
(f2 (lambda (fi p c)
(if (> count n)
prod
(fi fi (* c p) (+ c 1))))))
(f1 f2)))
?- p(X).Your answer must include a Prolog search tree similar in appearance to the ones in the textbook. The built-in precicate asserta adds its argument to the front of the database. It can be resatisfied, although its side-effect (changing the database) cannot be undone. Likewise retract permanently removes its argument from the database. The built-in predicate call tries to satisfy its argument as a goal; the infix predicate \== is 'not equal'. The built-in predicate fail forces backtracking. It is NOT suffcient to just run it and report the result - you must show that you understand how it works.
p(L) :- q(X,cat(X),L). q(X,G,_) :- asserta(x(0)), call(G), asserta(x(X)), fail. q(_,_,L) :- g([],M), !, L = M. g(S,L) :- n(X), !, g([X|S],L). g(L,L). n(X) :- retract(x(X)), !, X \== 0. cat(andy). cat(mandy).