logoalt Hacker News

xliitoday at 8:14 AM0 repliesview on HN

Someone bashing on my pet language? Cracks knuckles

Just kidding. Some of those are stylistic choices I don't have gripes but can understand the criticism. There is however one thing about "Non-cuts are confusing" I'd like to clarify:

In this example:

    foo(A, B) :-
      \+ (A = B),
      A = 1,
      B = 2.
It's very obvious why it fails and it has nothing to do with non-cut. Let's say A can be apple and B can be orange and now you're asking Prolog to compare apples to oranges! ;)

In short one has to "hint" Prolog what A and B can be so then it can "figure out" whethever comparison can be made and what is its result. Assuming there exist is_number(X) clause that can instantiate X as a number following would work just fine:

    foo(A, B) :-
      is_number(A),
      is_number(B),
      \+ (A = B),
      A = 1,
      B = 2.
(note that this would be stupid and very slow clause. Instantiation in such clauses like is_number(X) usually starts with some defined bounds. For A = 10000, B = 10001 and lower bound of 1 pessimistic case this clause would require 100M checks!