1

(Details of my miniKanren in Racket setup appear at the bottom[1].)

The way quotes and unquotes work in The Reasoned Schemer appears not to match the way they work in Racket. For instance, verse 2 of chapter 2 suggests[2] the following function definition:

(run #f
     (r )
     (fresh (y x )
            (== '(,x ,y) r )))

If I evaluate that, I get '((,x ,y)). If instead I rewrite it as this:

(run #f
     (r )
     (fresh (y x )
            (== (list x y) r)))

I get the expected result, '((_.0 _.1)).

This might seem like a minor problem, but in many cases the required translation is extremely verbose. For instance, in exercise 45 of chapter 3 (page 34), the book provides, roughly[3] the following definition:

(run 5 (r)
     (fresh (w x y z)
            (loto (('g 'g) ('e w) (x y) . z))
            (== (w (x y) z) r)))

In order to get the results they get, I had to rewrite it like this:

(run 5 (r)
     (fresh (w x y z)
            (loto (cons '(g g)
                        (cons (list 'e w)
                              (cons (list x y)
                                    z))))
            (== (list w (list x y) z)
                r)))

[1] As described here, I ran raco pkg install minikanren and then defined a few missing pieces.

[2] Actually, they don't write precisely that, but if you heed the advice in the footnotes to that verse and an earlier verse, it's what you get.

[3] Modulo some implicit quoting and unquoting that I cannot deduce.

Jeffrey Benjamin Brown
  • 3,427
  • 2
  • 28
  • 40
  • 4
    Looks like you should use [`quasiquote`](https://docs.racket-lang.org/reference/quasiquote.html#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._quasiquote%29%29) instead of `quote`. – user4003407 Nov 16 '18 at 05:31
  • 1
    quasiquote is the one written with a backtick ( `` ` `` ) which is on the same key as tilde (`~`), not the normal tick (`'`) – Alex Knauth Nov 16 '18 at 06:12
  • That was the problem. Thanks! – Jeffrey Benjamin Brown Nov 16 '18 at 18:31
  • 1
    Also note that `(cons '(g g) (cons (list 'e w) (cons (list x y) z)))` can be written as `(list* '(g g) (list 'e w) (list x y) z)`. – user4003407 Nov 17 '18 at 18:32
  • @PetSerAl If z is a proper list, that is true. That section of the book, though, delves into the problems associated with improper lists. – Jeffrey Benjamin Brown Nov 17 '18 at 19:32
  • 1
    @JeffreyBenjaminBrown Can you show example when this is not true? Assuming `cons` and `list*` have their normal definitions, AFAIK, `(list* a b c d e)` should be the same as `(cons a (cons b (cons c (cons d e))))`. https://www.ideone.com/rxqmB5 – user4003407 Nov 17 '18 at 19:52
  • @PetSerAl Consider a simpler example: `(list 1 3)` = `(1 3)`, while `(cons 1 3)` = `(1 . 3)`. The first is a proper list, the cdr of which is `(3)`. The second is an improper list; its cdr is `3` instead of `(3)`. – Jeffrey Benjamin Brown Nov 17 '18 at 19:59
  • 1
    @JeffreyBenjaminBrown `(list 1 3)` is `(1 3)`, but `(list* 1 3)` is `(1 . 3)`. – user4003407 Nov 17 '18 at 20:02
  • Thanks! My bad. I didn't know about `list*` and read it as `list`. – Jeffrey Benjamin Brown Nov 17 '18 at 20:08

1 Answers1

2

Use the backquote ` instead of the simple quote ' you have been using.

Will Ness
  • 70,110
  • 9
  • 98
  • 181