Hello!
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.
(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, respectivelyHowever, I'm getting ()
for both when I eval then with CIDER. Am I doing something incorrectly?
, is ~
,
is unquote in scheme and whitespace in clojure
~
is syntax-unquote in clojure
Awesome, thank you~
Wonderful, that's working~
(run* [q]
(fresh [x]
(== `(~x) q)))
HM, I still must have something wrong because these two are evaluating incorrectly:
(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])))
Cool, thank you -- I'll try replacing the lists with vectors when I hit a snag like this again.
Awesome, I was able to get through chapter 1! https://github.com/kellyi/clj-lisp-sandbox/blob/master/reasoned-schemer/src/reasoned_schemer/one.clj