>From what I have read till now I got the impression that conde in 
minikanren is somehow an OR condition and a list of expressions is somehow 
an AND condition. But that seems to be wrong. Maybe anyone can point out 
where I did a mistake?

I tried to implement the following boolean condition as a minikanren 
program.

(define (host-bool h a l)
  (and
   ;; application
   (or (equal? a "browser")
       (equal? a "server")
       (equal? a "proxy"))
   ;; location
   (or (equal? l "home")
       (equal? l "work")
       (equal? l "isp"))
   ;; host
   (or (and (equal? h "notebook") (equal? a "browser") (equal? l "home"))
       (and (equal? h "tower")    (equal? a "server")  (equal? l "work"))
       (and (equal? h "cluster")  (equal? a "proxy")   (equal? l "isp")))))

The function checks if A is one of the three applications, and if L is one 
of the three locations and checks if H matches the host per application and 
location.

The function succeeds for valid input and fails for invalid input.

(host-bool "cluster" "proxy" "isp") ;; => #t
(host-bool "cluster" "proxy" "###") ;; => #f

My aim was to have a consistency check for application and location. If the 
host definition is not consistent with the application and location 
requirements the function fails. This would be an inconsistent definition, 
because (and (equal? l "isp") (equal? l "###")) fails.

(define (buggy-host-bool h a l)
  (and
   ;; application
   (or (equal? a "browser")
       (equal? a "server")
       (equal? a "proxy"))
   ;; location
   (or (equal? l "home")
       (equal? l "work")
       (equal? l "isp"))
   ;; host
   (or (and (equal? h "notebook") (equal? a "browser") (equal? l "home"))
       (and (equal? h "tower")    (equal? a "server")  (equal? l "work"))
       (and (equal? h "cluster")  (equal? a "proxy")   (equal? l "###")))))

The function fails for location "isp" and "###":

(buggy-valid-host "cluster" "proxy" "isp") ;; => #f
(buggy-valid-host "cluster" "proxy" "###") ;; => #f


Now I tried to do the same in minikanren with lists and conde's:

(define (host h a l)
  ;; application
  (conde
    ((== a "browser"))
    ((== a "server"))
    ((== a "proxy")))
  ;; location
  (conde
    ((== l "home"))
    ((== l "work"))
    ((== l "isp")))
  ;; host
  (conde
    ((== h "notebook") (== a "browser") (== l "home"))
    ((== h "tower")    (== a "server")  (== l "work"))
    ((== h "cluster")  (== a "proxy")   (== l "isp"))))

At first glance it works as expected. The program enumerates all valid 
combinations:

(run* (h a l) (host h a l))
;; => (("notebook" "browser" "home") ("tower" "server" "work") ("cluster" 
"proxy" "isp"))

But when I have an inconsistent definition the results differ.

(define (buggy-host h a l)
  ;; application
  (conde
    ((== a "browser"))
    ((== a "server"))
    ((== a "proxy")))
  ;; location
  (conde
    ((== l "home"))
    ((== l "work"))
    ((== l "isp")))
  ;; host
  (conde
    ((== h "notebook") (== a "browser") (== l "home"))
    ((== h "tower")    (== a "server")  (== l "work"))
    ((== h "cluster")  (== a "proxy")   (== l "###"))))

Here the "isp" and "###" do not match. But instead of failing the 
inconsistent values are returned:

(run* (h a l) (buggy-host h a l))
;; => (("notebook" "browser" "home") ("tower" "server" "work") ("cluster" 
"proxy" "###"))


Why is it so? Where is the OR condition between (== l "isp") and (== l 
"###")? Why isn't there an AND?

-- 
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