MiniKanren caro

Similar to car.

Relation which asserts first item in list equivalent to x for goal == #s:

(caro (grape raisin pear) x) ;; #s iff x == grape

;; (grape)

Definition

(define caro
  (lambda (p a)
    (fresh (d)
      (== (cons a d) p))))

car takes 1 argument (a list) caro takes 2 arguments (a list p and a variable a)

Also observe this is declarative.

We simply say that given a list p and a variable, a, a appended to a fresh variable has to give us p.

It does not talk about the procedure we go through to get the head element of the list.

We do not deconstruct p.

With conso

(define caro
  (lambda (p a)
    (fresh (d)
      (conso a d p))))