logoalt Hacker News

YeGoblynQueenne11/07/20240 repliesview on HN

There's no -/2 operator in the initial definition of lookup/3 though:

  lookup(Key, dict(Key,X,Left,Right), Value) :-
      !
      ,X=Value.
  lookup(Key, dict(Keyl,X,Left,Right), Value) :-
      Key < Keyl
      ,lookup(Key,Left,Value).
  lookup(Key, dict(Keyl,X,Left,Right), Value) :-
      Key > Keyl
      ,lookup(Key,Right,Value).
You can also see that in the first call to lookup/3 where there's no -/2.

If I understand correctly, that's what the OP is asking: Where did the -/2 come from, not what it's for.

The call with the -/2 is under the heading "Refactoring the dictionary" so it's possible the author mixed up the implementations while writing the article and listed the output of an implementation that represents key-value pairs as -/2 terms.

The refactored version makes more sense btw and indeed I see the author switches to K-V later on in the article.