Fork me on GitHub
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?


, is unquote in scheme and whitespace in clojure


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


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


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


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


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