From Esolang
Jump to navigation Jump to search

Brachylog is not a declarative language

Since Brachylog and Prolog are based on similar paradigms, this proof demonstrates that Prolog is technically not a declarative language. Take this Prolog program as an example:

sort_list(Input, Output) :-
  permutation(Input, Output),
check_order([First, Second | Tail]) :-
  First =< Second,
  check_order([Second | Tail]).

This sorts a list; it is quite easy to understand, right? However, this program simply returns a list with all permutations and checks whether the permutations are sorted using a kind of linear fashion like C++ and Java. Also it uses recursion to check the whether the orders are correct using a looping construct. This can be re-written in another way in a procedural language using pretty much the same idea. --(this comment by A at 03:38, October 6, 2019‎ UTC; please sign your comments with ~~~~)

for i in all_permutations(input):
    for k in i:
        if i[i.index(k)+1] <= k:

Therefore Prolog is technically a procedural language with some advanced constructs that help people to develop more naturally. This applies to Brachylog too.

The big difference is that Prolog and Brachylog allow you to perform operations on variables before you assign them. permutation isn't implemented like that – it's effectively imperative, like you point out – but many other operations are. So you can write code like X = [1, 2], concat(X, Y, Z), Y = [3, 4] in Prolog, in order to set Z to [1, 2, 3, 4]. In C, you couldn't write the code in that order (trying to brute-force through all possibilities for Z would be massively inefficient). A similar example would be code like A + B #= 4, A * B #= 4, which would set both A and B to 2, and which doesn't easily translate to an imperative language because you can't convert A + B #= 4 into a loop over all integers because there are infinitely many of them.
Even within your example, you're hiding a major difference between C's and Prolog's control flow: your continue isn't a direct translation of anything in the original Prolog, and if you made the Prolog more complex (including, e.g., returning from a predicate before the failure occured), you'd have problems finding an equivalent in the C code. --ais523 20:04, 6 October 2019 (UTC)