Here's my attempt at implementing an example of a "does not exist" relation 
in core.logic:

(ns diplomacy.vote
  (:refer-clojure :exclude [==])
  (:use [clojure.core.logic])
  (:require [clojure.core.logic.pldb :as pldb]))

;; `voter-name` voted for `candidate`
(pldb/db-rel vote voter-name candidate)

(def voter-db (pldb/db
               [vote "Peter" :blue]
               [vote "Sarah" :blue]
               [vote "Larry" :red]
               [vote "Steve" :red]
               [vote "Amy" :yellow]))

(defn candidate-received-no-votes
  "Relation where candidate `candidate` received no votes"
  [candidate]
  (fresh [voter candidate-with-votes]
    (conda
     [(vote voter candidate)
      (!= candidate candidate-with-votes)]
     ;; No candidate received a vote, so `candidate` received no votes
     [succeed])))

diplomacy.vote> (run-db* voter-db [q] 
(diplomacy.vote/candidate-received-no-votes 
:blue))
((_0 :- (!= (_1 :blue))) (_0 :- (!= (_1 :blue))))

This result makes sense because unification succeeds as long as 
`candidate-with-votes` is not `:blue` (though I'm not sure why there's two 
results). However, this is not what I wanted: the run should 'fail' because 
the candidate `:blue` received at least one vote.

The only other thing in the core.logic API 
<http://clojure.github.io/core.logic/> that looked promising was `nafc`:

(defn candidate-received-no-votes
  "Relation where candidate `candidate` received no votes"
  [candidate]
  (fresh [voter]
    (nafc vote voter candidate)))

diplomacy.vote> (run-db* voter-db [q] 
(diplomacy.vote/candidate-received-no-votes 
:blue))
((_0 :- (clojure.core.logic/nafc #function[clojure.lang.AFunction/1] _1 
:blue)))

This constraint this produces makes sense, but I believe the only correct 
answer to my query is getting no results: ()

I'm struggling to think of a correct implementation of 
`candidate-received-no-votes`. Can anyone provide a correct implementation, 
or point me in the right direction?

-- 
You received this message because you are subscribed to the Google Groups 
"minikanren" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/minikanren.
For more options, visit https://groups.google.com/d/optout.

Reply via email to