| No functions: You can't do length + 1 as a single expression in any language though, in python for example len(ls) + 1 is two expressions, but I get what you mean, it is a little less terse. But those commas in prolog are super useful. And you can make your example bidirectional too: ```
:- use_module(library(clpfd)). foo(List, X) :-
length(List, Out),
X #= Out + 1.
``` ```
?- foo(X, 3).
X = [_, _] . ?- foo(X, 3), X = [a,b].
X = [a, b] .
``` ----- No standarized collection types: I think that's a feature rather than a bug. The ability to just use infix and compound terms in a generic way without it being tied to a clause or operator is a huge feature. For example: ```
pets(dog-rex-poodle, dog-fluffy-bishon).
``` That defines the collection in a semantic or mathematical sort of way, then you can pass that into whatever data structure you want, whether it's a ordered map or a hashmap or whatever. ---- No boolean values: That's also a feature in prolog, same as having no null. It's the same sort of motivation for Haskell's Maybe and Either types or Rust's Option and Result types, same kind of usefulness. ---- Cuts are confusing: Conditionals don't need to use cuts, the modern prolog way of doing it is using the reif library: ```
:- use_module(library(reif)). if_(Cond, Then, Else)
``` For example: ```
:- use_module(library(clpfd)).
:- use_module(library(reif)). sign(X, S) :-
if_(X #> 0,
S = pos,
S = nonpos).
``` --- Non-cuts are confusing: This isn't doing what you're thinking: ```
\+ (A = B)
``` It's unifying A with B, `A = B` unifies. You want `dif(A, B)`. ---- Straying outside of default queries is confusing: It might be tempting to use bagof, but it's not monotonic. You should try to write as much prolog code as you can in a pure, monotonic way, so your code can take advantage of prolog's unique advantages, like monotonic debugging. Check out the SWI prolog discourse group, there's a lot of good stuff in there and everyone's very supportive to newbies. And Markus Triska's website and youtube channel Power of Prolog is a super useful resource for all this stuff, a good place to go if you want to know what sets prolog apart. A lot of prolog's usefulness doesn't show up as an embedded language either, like minikanren isn't "pretty much prolog", it lacks a lot of stuff that prolog offers. Multiparadigm programming languages are also really popular now, but a lot of what sets programming languages apart isn't what they can do, it's what they can't do, what sort of paradigm or way of thinking they force you to adopt. |
x = length(list) + 1
On the other hand I don’t really see why it is an issue with Prolog (maybe there are more complicated situations than the example)