Some questions about declarative interpretation of not predicate in Prolog
This question already has an answer here:
I don't have much to add to what @hardmath said (+1) but it will take me more words to say it so it isn't a comment.
First, you're seeing a hard dichotomy between procedural and declarative, but there are other ways of looking at things and lots of things sit sort of in the middle. +
is one of them, because it has a mostly-declarative reading, but where the declarative reading falls short has to do with it being executed on a machine. But all of Prolog is executed on a machine, and it doesn't mean that you're never able to think declaratively. It's not an all-or-nothing proposition. The so-called extralogical or meta predicates setof/3
et. al. furnish you with results that are not, strictly speaking, first order logic, but that doesn't mean they're procedural or even necessarily that they're implemented in an overtly procedural way. In short: there are more things than "procedural" and "declarative" in the universe, and it isn't always cut and dry which are which.
Second, you insist on reading conditional logic as inherently procedural. I think this is a fixation on a low-level detail. Yes, you can write Prolog with a lot of red cuts and which only admit a procedural reading, but simply using if/then logic doesn't necessitate that, nor is it a slippery slope from one to the other. You seem fixated on reading "if X then Y else Z" as "First, you do X, then if that succeeds you do Y, or if it failed, then do Z." But you don't have to read it this procedurally, and in fact you probably should not. Even though ordering the conditions affects the performance and sometimes the correctness, you don't need to let it obliterate the declarative reading for you. After all, in any language this will be true to one extent or another, thanks to the halting problem and the fact that we execute programs on machines. If we let that poison our understanding even in Prolog, we'll never be able to escape from it or realize the benefits of declarative programming. In short: if/then/else need not be understood as inherently procedural.
So to sum up: relax. :)
链接地址: http://www.djcxy.com/p/66934.html