Fork me on GitHub
#core-logic
<
2019-02-23
>
Kelly Innes05:02:37

I'm trying to work through latest edition of the The Reasoned Schemer in Clojure and I'm encountering some Scheme syntax I don't quite know how to translate.

Kelly Innes05:02:55

(run* [q]
  (== `(((,q)) pod) '(((pea) pod))))

(run* [q]
  (== '(((pea)) pod) `(((pea)) ,q)))
are analogues for chapter 1, frame 33 and 34, and should associate q with pod and pea, respectively

Kelly Innes05:02:23

However, I'm getting () for both when I eval then with CIDER. Am I doing something incorrectly?

hiredman05:02:45

, is unquote in scheme and whitespace in clojure

hiredman05:02:02

~ is syntax-unquote in clojure

Kelly Innes05:02:49

Awesome, thank you~

Kelly Innes05:02:55

Wonderful, that's working~

Kelly Innes05:02:01

(run* [q]
  (fresh [x]
    (== `(~x) q)))

Kelly Innes05:02:46

HM, I still must have something wrong because these two are evaluating incorrectly:

Kelly Innes05:02:47

(run* [q]
  (== '(((pea)) pod) `(((pea)) ~q)))

(run* [q]
  (fresh [x]
    (== `(((~q)) ~x) `(((~x)) pod))))

yuhan06:02:10

that's due to the auto namespacing of symbols in syntax-quoted forms

yuhan06:02:34

ie. the first pea is a regular non-namespaced symbol but the second expands to your-ns/pea

yuhan06:02:30

I think a much more idomatic way of doing this in Clojure is using vectors

yuhan06:02:51

(run* [q]
  (== [[['pea]] 'pod] [[['pea]] q]))

(run* [q]
  (fresh [x]
    (== [[[q]] x] [[[x]] 'pod])))

Kelly Innes16:02:21

Cool, thank you -- I'll try replacing the lists with vectors when I hit a snag like this again.