简体   繁体   中英

Prompt does not come back

I try to do some exercise - to represent numbers in "s representation" which means '0' is zero, s(0) is 1, s(s(0)) is 2 and so on. I tried to write predicate for adding "s numbers": the predicate s2int convert "s number" to int.

s2int(0, 0).
s2int(s(X), Y) :-
   s2int(X, Y1),
   Y is 1 + Y1.

add(X, Y, Z) :-
   s2int(X, SX),
   s2int(Y, SY),
   s2int(Z, SZ),
   SZ is SX + SY.

When I query add it writes the correct answer but the prompt does not come back. What's the problem?

Your definition of add/3 works fine, and also terminates, if all three arguments are given. If you leave one of them as a variable, one of the goals s2int(XYZ, SXYZ) has then two uninstantiated variables as arguments. It describes thus an infinitely large set, whose complete enumeration takes infinitely long.

Not sure what you are after, but probably you want to define add/3 for successor arithmetics. You can do this, without resorting to the 0,1,2 integers! Try it! Otherwise search of .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM