| >> The problem was that it was too stupid. It's ... a programming language? It's Turing complete. Nobody said it's
intelligent. >> It's imperative (ha!) for the Prolog programmer to make sure that clause A is tried before B. That is one of those cases where Prolog takes the pragmatic approach to allow
efficient computation rather than sticking to "pure" semantics of the kind
that tends to make a big mess of things just to keep things "clean" (like, oh,
I don't know... monads?). Btw, I've written reams and reams of Prolog in the last five or six years. The
fact that your code has two readings, declarative and imperative is only a
problem if you allow your mind to remain stuck in some purist definition of
declarative programming that looks beautiful but doesn't really work. If you accept that we live in an imperfect world, have to contend with
primitive computers and limited resources of all kind, then Prolog is fine and
miles and miles ahead of anything else in terms of declarative semantics. Even
lisps have magickal and mysterious stuff like eval etc. In actual Prolog programming practice the imperative reading means you can
actually debug your code and follow it around as it falls over your own bugs.
A purely declarative program would also be purely undebugable. The dual semantics is only a problem if you don't understand the language. And in what language is that not what you'd expect? >> Prolog programmers frequently exploit the left-to-right, depth-first strategy
by using the operator known as the "cut". No, let's say things the way they really are. The cut is there to allow a
branch of the depth-first tree to be, well, cut. Correct, its semantics are
purely imperative. Its real use though is to stop unnecessary searching and
backtracking and therefore make your program more efficient. It's not there to "exploit" anything. The fact that it can be exploited is
troublesome, but so is all sorts of stuff in programming, like buffer overruns
or sql injection. It sucks, but ... imperfect world, scarce resources etc. >> your algorithm is exponential in the typical case What? Why does your algorithm have to be exponential if it's in Prolog? What the hell are you on about? |
But I was trying to explain why Prolog is not the declarative language that we all hope for (well, a lot of us do, anyway) and that it initially appeared, to some, to be. And I think the answer to that is exactly what I said. That doesn't mean it's not a useful tool!
> [The cut is] not there to "exploit" anything. The fact that it can be exploited is troublesome, but so is all sorts of stuff in programming, like buffer overruns or sql injection.
Whoa! "Exploit" is a general term; it doesn't just refer to security vulnerabilities. Dictionary.com offers this definition for the verb: "to utilize, especially for profit; turn to practical account: to exploit a business opportunity". (The definition I would offer is "to take advantage of", which can mean to make use of a vulnerability, but doesn't have to: you can take advantage of a convenient feature of a program.)
So when I say people "exploit" the search strategy by using the cut, I mean only that they gain benefit from it; if the search strategy were not so well-defined, the cut would be unusable.
> Why does your algorithm have to be exponential if it's in Prolog? What the hell are you on about?
If you try to write a significant Prolog program without understanding the search strategy, as if it really were a declarative language, your program will wind up being exponential or worse. Merely throwing hardware at this problem won't fix it. That's all I'm saying. I agree I didn't say it well the first time.