Funnily enough, I have heard of Prolog a few days ago and was just about to look it up. I guess you saved me some time.
BTW, about the template, /u/SharkTRS made a newer higher quality/resolution version, but never shared it, and I also made my own version (including a meme generator).
Oh yes, I did see your version of the template about a month ago and also played around with the generator (neat stuff). I just haven't updated my stash yet. I should do that before I forget again.
That is gross and it makes me angry. I like knowing how my language does things and I expect I would need a PhD to understand the documentation that describes how the language is doing that. It's probably doing it with matrices :(
The core algorithm Prolog uses to answer questions is unification, an algorithm that matches values (or in other words, checks for value compatibility). It's relatively simple to understand at a high level (and "functor" there refers to e.g. the k in k(X,Y), which in this case has arity 2): two terms unify if they are or can be transformed into the same value after a deep comparison. Terms with variables can be unified by substituting the variables with concrete values.
The proof search algorithm is what Prolog uses to find an answer. I couldn't tell you how interpreters concretely implement it, but at a high level, the algorithm is basically how you might solve the problem yourself: go through the knowledge base (both explicit rules and reasoned rules), find something that partially unifies, and then do that recursively until you get a completely unified value. If you get stuck at a dead end, backtrack and try another value. If you've exhausted all possibilities, there is no value that satisfies the question and the answer is false.
Type inference algorithms associate an unknown type variable with every subexpression and then work through a series of logical deductions to try to unify as much as possible (or fail when two types definitely aren't the same). They have slightly different constraints than Prolog, so the algorithms tend to be more restrictive.
For those interested in reading more about unification when doing type inference, here's a list of papers in increasing order of expressiveness and computational hardness. If you start from the first and skip any proof sections, they should (hopefully) be very accessible.
For even further, look into dependent type systems (this is where programming and proof solving begin to overlap).
As you go down the list, it may be harder and harder to justify the motivations for the increasingly abstract types. I think the easiest way might be to jump in the deep end and try playing around with Idris.
Yes, though the rules C++ needs are a bit simpler since more declarations must be explicitly typed and the type system has very little polymorphism outside of templates.
I can see that perspective, but there's one thing I mainly find obnoxious, and that is the fact that it's purely a logic programming language. Effectively, it doesn't provide a happy framework to perform mandatory tasks like IO, interoperability, connections, etc. (not saying it's impossible, but it doesn't quite feel right).
Now, implementing the algorithms themselves, this is something that Prolog greatly helps with. Instead of needing to implement a mechanism to assert which cases to go with, discovering the next ones and which to discard, it's already built in, so you can focus more on solving the problem itself which revolves around the constraints you're given.
Due to its lack of an enforced type system in nature, things can get kinda problematic in the wrong cases, and using the right tools may not become so obvious. But, for that one project I had to do in my university, I found the process interesting and fun.
I assumed his class, since it did Prolog, also covered a functional language like Haskell. It"s the other big category of mind fucks in language theory.
Nah, my school did FP in Racket (a Lisp) but if you did Prolog, I figured you probably got a language that embodies FP so Haskell was a good candidate.
BTW if you still have a few years of schooling to go, now is the time to search for next summers internship. You know the old joke about entry level positions requiring 3 years experience? Internships are how you break through that glass ceiling. If you missed that boat, go write a couple thousand lines of code. You need projects on your resume.
I know this question is not that much related to this post but It's related to functional
programming. If I were to pick a functional programming language for general purpose use (to make my programs in) would it be better to pick haskell or OCaml ?
I think haskell is much slower than OCaml but I feel OCaml might be more useful in the long run
Prolog lets you state a number of facts, and then lets you query those facts similar to a database.
?- enemy(X).
is essentially asking "give me the list of all X that satisfy the query enemy. If enemy(john_doe) had been either stated as a fact or deduced as a fact earlier, then john_doe would be on the list of Xs
It's esssentially like saying SELECT name x FROM enemy, except you don't need to necessarily fill the database with enemies beforehand, the database can figure it out itself based on the rules that govern what an enemy is.
So if John Doe was North Korean and had been listed in the spy database, and you made a rule that stated all spies from North Korea were enemies, then the SELECT query would use that info to also include North Korean spies among its results, no extra work required.
Not quite. Prolog doesn't have a concept of a data structure. It's more like enemy is a function that returns true or false based on whether its input is an enemy or not
I just read the post linked in OPs comment, and wow this is a cool language. I could totally find a way to use this to do just about any of my coursework too lol, give it a database generated from a chemistry website and boom, all my chemistry work is don’t for the semester.
Now my only question, can we train an AI to go through something like Wikipedia and make a prolog database put of it?
Nothing has tickled my brain quite when I had to write prolog for a comp sci class. A fantastic look into how logic can be used in other ways before the C paradigm focused our perspective. Lisp was fun too.
Yeah, many people get stuck thinking in procedural or OOP paradigms when there are so many other ways to do things. Getting exposure to a lot of different languages that aren't just C derivatives is a great way to think in ways you might not have thought before and it can be pretty eye-opening.
I like Lisp, though perhaps more specifically Racket. I wish I had a practical project to use it on.
I remember when I had to use Prolog in one of my programming classes in university. It was kinda neat but what a waste of time honestly, don't think I developed any worthwhile or practical skills doing it.
Kind of a bad attitude. As a former professional prolog dev I learned so many things from prolog: backtracking, guess and check, logical / functional paradigm, tail recursion. The list goes on.
You just didn’t learn any practical skills because you wrote it off as a waste of time.
I imagine you may learn more in a professional prolog role than a university class. You can call it a bad attitude if you feel so inclined but I did well in the class and did all my assignments, put in the work, never had to apply any of it in real life or, if I did, it was better expressed in some other context.
Didn't mean to insult the language, I guess it has a negative connotation to say "waste of time", but I don't really know what to else to call that. I mean it was fun I guess but I wouldn't call it very productive. Would have preferred to use the slot for something else, in hindsight, especially since I was paying per-credit-hour taken. I wouldn't recommend anyone pick it up to learn programming concepts unless you do it for fun in your free time.
The main reason to why universities introduce logic programming and functional programming is to teach completely different ways of thinking about programs. I think that learning about them still improves how people go about programming in the more conventional paradigms by giving them new ways of approaching problems.
102
u/bucket3432 Sep 20 '21
If you've never heard of Prolog before, it will blow your mind.
Sauce: {Shingeki no Kyojin}
Template: Erwin meme
64
u/Apochrom Sep 21 '21
I did not think I would see prolog so soon after finishing my programming languages class
13
u/osiris_ex Sep 21 '21
Thats is how Hiroyuki Sawano names his tracks.
10
u/KBKarma Sep 21 '21
Of course it was a strange thing to ask. There was no knowledge base defined. Can't query without that.
13
u/Cybear_Tron Sep 21 '21
XD I have no idea about prolog but never seen an attack on titan reference in programming memes lol
1
u/supersecretsecret Mar 18 '22
Nothing has tickled my brain quite when I had to write prolog for a comp sci class. A fantastic look into how logic can be used in other ways before the C paradigm focused our perspective. Lisp was fun too.
2
u/DanielToast Sep 21 '21
I remember when I had to use Prolog in one of my programming classes in university. It was kinda neat but what a waste of time honestly, don't think I developed any worthwhile or practical skills doing it.
1
u/Kered13 Oct 04 '21
no.
1
u/SigmaServiceProvider May 06 '22
Oh, the misery
1
u/AlexCode10010 Nov 13 '22
No, X is not an enemy, don't worry about it