/* Define a Prolog predicate replicate/3 which corresponds to
* the Haskell function of the same name, except that the numeric
* argument is expressed symbolically.
*
* For example, replicate(s(s(s(0))),a,[a,a,a]) should be satisfied.
*/
到目前为止,我已经找到了这个解决方案:
replicate(0,_,[]).
replicate(X,Y,[Y|Z]) :- replicate(p(X),Y,Z).
但问题是 s(s(s(0))) 没有被 pred 函数减少。它导致 p(p(p(s(s(s(0))))))
你们能帮帮我吗?