Earlier quoted context omitted.
I did not say "can't do". I essentially said "not as well". Of course "well" can be subjective, but if enough people don't like way a given language/tool does it, they will ignore it, like they have been with FP/logical programming for several decades. Somebody needs to articulate in careful unambiguous detail how and why it's "better" and "easier", not just repeatedly claim it. That writer apparently hasn't been bor…
You seem to be moving the goalposts to "why is FP better than X". I was simply pointing out that printf debugging is easy in FP. In fact, it's probably easier in FP, since everything is an expression, whereas imperative languages have a weird expression/statement distinction. For example, if I have code like: buggyCode x y = if foo x then bar x y else baz y I can wrap anything on the right-hand-side in a printf (exce…
The Power of Prolog
141–150 of 162 posts
Re: The Power of Prolog
#142Earlier quoted context omitted.
Prolog is ideal for some kind of problems, good programmers should know what logic programming is and what problems are perfect for logic programming, then if in real life you hit such a problem you can chose prolog or a library that does logic programming.
I'd like to see a comparison to the alternatives to illustrate objective benefits. I've been down that road before in my-language-can-beat-up-your-language debates, and the end result is usually, "Well, my approach looks easier and simpler TO ME; you just think wrong." Other times they do queries in the app language when they should be using a database.
It is like recursion, some problems can be solved nice with recursion but you do not use recursion everywhere. Also you can use a library in your favorite programming language and not use prolog, examples were presented in this thread.
My point is that a good programmer should know about the concept not to use it everywhere, I never had the chance to use prolog so far for my work.
Btw I am also past the stage where I have a favorite language and OS, every piece of software has it's issues.
Re: The Power of Prolog
#143Earlier quoted context omitted.
That makes Prolog look downright useful! I heard from lots of people that it's fun as an esoteric language and some had a homework assignment or two in it, but nobody really uses it in practice. Do you think this might be more useful as a module to solve logic puzzles, rather than as a complete language by itself? I learned the very basics, but not worked with it enough myself to say whether that would be better than…
Well, the idea that "nobody really uses it in practice" doesn't hold up to the evidence in this thread, eh? It's used and under active development. I think it lacks hype. :-) > Do you think this might be more useful as a module to solve logic puzzles, rather than as a complete language by itself? I was thinking about it this morning and I came to the conclusion that Prolog really is AI. They did it. We have AI alread…
What makes you think that? I don't think we have a clear idea of what the brain does when doing "intelligent" things, but syntactic unification is very probably not it. For whatever it's worth, the CLP(FD) stuff you posted isn't "just" unification, it needs additional powerful constraint solving algorithms behind it to work as well as it does.
All that unification does is solve simple equations between terms without knowing anything about what is going on:
?- f(X, b) = f(g(a), Y). % query
X = g(a), % solution
Y = b.
This is nice, but it's not exactly intelligence.Yay for Prolog enthusiasm! I like calling it "magical" too. But let's not go overboard with grand AI claims.
Re: The Power of Prolog
#144Earlier quoted context omitted.
This Python code does a full search and finds the unique solution instantly: p = 711 q = 711000000 for a in range(1, 1 + p // 4): if q % a == 0: for b in range(a, 1 + (p - a) // 3): if q % (a * b) == 0: for c in range(b, 1 + (p - a - b) // 2): d = p - a - b - c if a * b * c * d == q: print (a, b, c, d) Does Prolog do the same pruning? Alternatively, it could be dumber (omit some of the pruning that my code does) or s…
Prolog doesn't do that automatically, but you can write the same thing in Prolog too: xkcd_ugly(A, B, C, D) :- P = 711, Q = 711000000, Max_A is 1 + P // 4, between(1, Max_A, A), Q mod A =:= 0, Max_B is 1 + (P - A) // 3, between(A, Max_B, B), Q mod (A * B) =:= 0, Max_C is 1 + (P - A - B) // 2, between(B, Max_C, C), D is P - A - B - C, A * B * C * D =:= Q. In SWI-Prolog, I get the following timings: ?- time(xkcd_ugly(A…
Re: The Power of Prolog
#145Earlier quoted context omitted.
PicoLisp has one.
If you are talking about the Pilog "Prologue Engine" it really is not the same thing at all as a proper Prolog.
Re: The Power of Prolog
#146Earlier quoted context omitted.
Regarding your last sentence: Yes, I can confirm that this has happened, to a reasonable extent of "learned" in the sense that people went on to write programs using this material. However, I do not know how common this is, since I almost exclusively get feedback from those who found the material suitable. There were definitely complete beginners among them. For instance, here is a discussion that happened a few mont…
Cool, good to see others are finding this useful. > In my experience, learning Prolog properly requires dedicated guidance, and it would be highly unusual to achieve mastery without it. There are two readings of this sentence. An unkind spirit might think you are saying that Prolog books cannot make you a master for some inherent reason related to Prolog, independent of any book. Whereas I would say that there is no…
In addition, for social and other reasons, you cannot write down in a book everything that advanced Prolog students should know. As a consequence, some things are better said than written, and I therefore think that a book alone is unlikely to be sufficient.
Re: The Power of Prolog
#147Prolog loses a lot of its magic when you realize it's just DFS the language.
C loses a lot of its magic when you realize it's just memory but with syntactic sugar.
Here is more information:
https://cs.stackexchange.com/questions/60965/is-c-actually-t...
In C, you can only represent an unbounded tape if you assume the existence of an unbounded stream, i.e., in a so-called hosted implementation of C where unbounded streams are available. But unbounded streams cannot be implemented in freestanding C, even if unlimited memory were available!
Re: The Power of Prolog
#148Earlier quoted context omitted.
Well, the idea that "nobody really uses it in practice" doesn't hold up to the evidence in this thread, eh? It's used and under active development. I think it lacks hype. :-) > Do you think this might be more useful as a module to solve logic puzzles, rather than as a complete language by itself? I was thinking about it this morning and I came to the conclusion that Prolog really is AI. They did it. We have AI alread…
> The Unification algorithm at the heart of Prolog (I'm not an expert!) is pretty much what your brain does when you solve logical puzzles and problems. What makes you think that? I don't think we have a clear idea of what the brain does when doing "intelligent" things, but syntactic unification is very probably not it. For whatever it's worth, the CLP(FD) stuff you posted isn't "just" unification, it needs additiona…
Direct observation.
I learned unification algorithm from studying Matthew Rocklin's Python Kanren implementation [1]. The next time I was thinking out the solution of a programming problem, as I was witnessing my brain (or mind if you prefer) solve the problem, I realized on a "meta-track" that what it was doing was exactly unification. I actually "saw" it happening and had a context to recognize and name it. I think it helped that I was working in a domain that has models very close to the forms (computer programming) but the rational logical thinking process is the unification algorithm.
> I don't think we have a clear idea of what the brain does when doing "intelligent" things
Well, I don't mean to suggest that rational thinking is the only kind of thinking! I'm just pointing out that it's a kind of thinking that really has been automated. It's AI. (Not all that AI is or ever will be, but it counts.)
Turing essentially made concrete the thought process of solving (some kinds of) math problems, noticed that the "atomic elements" of the process were a finite set, and designed a machine to automate those steps, so in a sense, computers have always been AI.
> CLP(FD) stuff you posted isn't "just" unification, it needs additional powerful constraint solving algorithms behind it to work as well as it does.
Yes, and the brain has powerful sensory systems attached to it. I think science has identified something like twenty-seven different human senses. These all supply "finite domains" to the reasoning system. The sensory systems are very active, and can function in "virtual" mode (aka imagination) to permit a kind of thinking by simulation (analogs.) Animals have this sort of thinking as well (that's why they can dream.)
The linguistic/digital system reifies this fast primary mode thinking into slower rational thinking distinctions and reasoning, which is then used to build coherent models of the world which are then used to generate behavior. [2] If you codify that thinking process you get the unification algorithm.
[1] https://github.com/logpy/logpy
[2] ...and behavior generates new sensory inputs... The whole thing constitutes a feedback loop linking the real world with your subjective experience. Linguistic thinking permits direct modeling of recursion, which permits thinking about open-ended loops in behavior in a concrete way, which permits self-referential modification of the reasoning structures, enabling rapid innovation in behavior (aka "culture".) You're a cybernetic process that can become a Gödel machine.
Re: The Power of Prolog
#149Earlier quoted context omitted.
I'd like to see a comparison to the alternatives to illustrate objective benefits. I've been down that road before in my-language-can-beat-up-your-language debates, and the end result is usually, "Well, my approach looks easier and simpler TO ME; you just think wrong." Other times they do queries in the app language when they should be using a database.
I don't think I understand your point, prolog is a logic programming language, some problems are easy to express like facts and rules so Prolog is a good solution, you can see examples in this HN thread of real usage. It is like recursion, some problems can be solved nice with recursion but you do not use recursion everywhere. Also you can use a library in your favorite programming language and not use prolog, exampl…
Re: The Power of Prolog
#150Earlier quoted context omitted.
You seem to be moving the goalposts to "why is FP better than X". I was simply pointing out that printf debugging is easy in FP. In fact, it's probably easier in FP, since everything is an expression, whereas imperative languages have a weird expression/statement distinction. For example, if I have code like: buggyCode x y = if foo x then bar x y else baz y I can wrap anything on the right-hand-side in a printf (exce…
That's another thing: "high-meta" languages allow individual developers to re-invent the flow-control wheel in their own image (personal preferences). Consistency is often more important for team readability than factoring (compact code). One man's "clever" can be another's spaghetti code. What works well for individual projects often doesn't scale to larger and often-changing teams.
As for that `ifThenElse` example, there's nothing "meta" going on at all and there's no fancy control flow: it's just a (very simple) function. Consider a function like:
renderPage User page register = page
renderPage Guest page register = register
Doesn't look like 'clever spaghetti' to me: we branch between 'User' and 'Guest', returning a different one of our arguments for each. Yet this is identical to that 'ifThenElse' function, except for the names (which are irrelevant to the machine).This is what I meant by writing "more meaningful, domain-specific alternatives". Not to "re-invent control flow", but to avoid talking about control flow, and just use functions.
Note that we can do pretty much the same in any language, e.g. Python:
def ifThenElse(c, x, y):
return {True: x, False: y}[c]
def renderPage(session, page, register):
return {User: page, Guest: register}[session]
Nothing "meta" or "re-inventing the flow-control wheel" there; just some functions. Of course, this isn't a great idea in Python since Python is impure and uses eager evaluation.Note that such "meta" "reinvented control structures" appear all over the place in OOP, due to dynamic dispatch, e.g.
class User:
def renderPage(page, register):
return page
class Guest:
def renderPage(page, register):
return register
These are the two solutions to the "expression problem":- FP restricts the allowed values but allows new functions to use them. For example, adding an Admin session would be hard (need to rewrite renderPage), but adding a renderAvatar function is easy.
- OOP restricts the allowed functions (methods), but allows them to use new values. For example, adding an Admin class would be easy, but adding a renderAvatar method would be hard (need to rewrite User and Guest).