core-logic

2019-02-23T05:29:58.000400Z

Hello!

2019-02-23T05:30:37.001200Z

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.

2019-02-23T05:32:55.002800Z

(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

2019-02-23T05:33:23.003500Z

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

2019-02-23T05:36:27.003700Z

, is ~

2019-02-23T05:36:45.004100Z

, is unquote in scheme and whitespace in clojure

2019-02-23T05:37:02.004500Z

~ is syntax-unquote in clojure

2019-02-23T05:37:49.004700Z

Awesome, thank you~

2019-02-23T05:39:55.004900Z

Wonderful, that's working~

2019-02-23T05:40:01.005100Z

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

2019-02-23T05:57:46.005800Z

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

2019-02-23T05:57:47.006Z

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

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

yuhan 2019-02-23T06:31:10.006600Z

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

yuhan 2019-02-23T06:33:34.007900Z

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

yuhan 2019-02-23T06:34:30.008600Z

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

yuhan 2019-02-23T06:34:51.008800Z

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

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

2019-02-23T16:07:21.009400Z

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

2019-02-23T18:34:18.009700Z

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

2