|
Map and other functional constructs may be declarative, but I only "feel" like I'm programming declaratively when I'm coding in a language like Prolog. The fact that, with unification and backtracking, you can not only get a result for a query, but also "pass a variable" as an argument and get a possible value makes it seem much more like a mathematical expression and less like a computation. For example, I can define some relations: parent_of(john, mary).
parent_of(mary, eve).
grandparent_of(X, Y) :- parent_child(X, Z), parent_child(Z, Y).
And then I can simply run a query: ?- grandparent_of(john, eve).
Yes
But I can also make it fill in the value for me: ?- grandparent_of(john, X).
X = eve
'grandparent_of' is not some piece of code, it's an actual declaration of a relation between the terms.Of course, you can do unification and backtracking in other languages, but Prolog is designed for it. |