4 ms·
> Prolog is a pretty standard functional programming language, just hidden in a backtracking query runner. Disagree. The fundamental difference (to me) is that
by dreamcompiler 4y ago
> Prolog is a pretty standard functional programming language, just hidden in a backtracking query runner.
Disagree. The fundamental difference (to me) is that in a functional language you write functions that have inputs and outputs. You can write code like this in Prolog, but Prolog encourages the idea that there's no such thing as an input or an output; there are only relations. If you write a function such as
c = a + b
in a functional language you cannot just say "here are c and a; tell me what b is." That idea makes no sense in a functional language, but Prolog will simply tell you what b is. You can even say "here is c; give me an assortment of a's and b's that make the relation true" and Prolog will start listing them off (albeit probably not very efficiently, and one does not typically use this capability for simple arithmetic).
This is a very different way of thinking about functions because they are inherently "bidirectional" and it's one of the things that makes Prolog feel more like a magical query language than a functional language.
- knome 4y agoThis works for simple little functions, but if someone was going to use prolog for anything complex, it would quickly be impossible. There aren't going to be functions that take a rendered page and an alist of values and return the template. Or that reverse hashing. Or really anything very complex. For using prolog in its original purpose as a database of queryable facts and rules, this is useful, but as a general purpose programming language, I think it's more of a parlor trick.
- dreamcompiler 4y agoI don't think it's really about "simple" functions per se. Bidirectionality is useful where function inversion is meaningful (i.e. not for hashing) and where the domain of the function is explicitly finite or otherwise bounded by constraints. That's exactly the situation when querying databases. Such queries can get quite complicated. Agreed that it's not that useful for GP programming, but it's very useful for databases and constraint management systems.