by OskarS · 7y ago · 0 comments
foo(X, Y) :-
some_condition(X),
!,
bar(Y, X).
foo(X, Y) :-
baz(X, Y).
to: foo(X, Y) :-
( some_condition(X)
-> bar(Y, X)
; baz(X, Y) ).
and get the same performance and clearer code.There are really very few actually useful uses of the cut in modern Prolog code. But we have no good, free, current teaching materials, so people get stuck learning the old ugly and convoluted ways.
Unfortunately since it's almost impossible to model ideas without stuff like the arrow, cut, or \+ (not) operators, writing actual pure logical Prolog programs that actually do interesting things is supremely difficult.
The ability to mix in impure features where needed is what makes Prolog practical.
'Logical' is a misnomer, Prolog is really a database query language. Unlike SQL it's not relational and not based on joins, it has tree walking semantics.
That said, without a decent storage/indexing system under the hood it is indeed quite pointless. Nobody wants a 'small data' tiny DB engine in 2019.