简体   繁体   中英

Turbo Prolog execution order

I'm trying to understand why am I getting the result that I am. Lets say that this is the code and result:

序言

Sorry if this is trivial, but there isn't too many sources online about this... If the output of d(3) makes sense to me, then e(3) doesn't at all. why does moving the write in cases like this reverse the order?
I'm guessing it has something to do with the recursion, but I'm still clueless at why.

This is because in the first case: You first write and then recursively call d(N1) , so for example d(3) will write 3 and then call d(2) etc...

In the second case: You first call e(N1) and then write and this changes the order because for example e(1) will call e(0) which will call e(-1) which will succeed and then e(0) will write 0 then e(1) will write 1 and so on...

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