core-logic

michele mendel 2021-01-26T18:52:19.012300Z

In https://github.com/clojure/core.logic/wiki/Differences-from-The-Reasoned-Schemer the pair? predicate is defined, but this will make the following true

(pair? '(a b c))          ;-> true
(pair? (lcons '(1 2) \s)) ;-> true
Isn't a pair (a . b) or (a b), not a list of more than 2 items?

2021-01-26T19:09:33.012500Z

no

2021-01-26T19:11:32.014200Z

in traditional lisps, lists are exposed linked lists of cells, each cell is like a 2 element array, one of the elements is called the car and one is called the cdr. those cells are what are pairs, that pair? returns true on in scheme

2021-01-26T19:12:41.015400Z

so (a . b) is a pair with the car a and the cdr b. (a b) is a pair where the car is a, and the cdr is (b), and (b) is a pair where the car is b and the cdr is nil

2021-01-26T19:13:16.016100Z

(a b c) is the same as the (a b) case extended by another level

2021-01-26T19:13:39.016500Z

https://people.csail.mit.edu/jaffer/r5rs_8.html#IDX319 is some documentation on the scheme function

michele mendel 2021-01-26T19:14:25.017200Z

Ah yes, I know about that. It's a cell, right?

2021-01-26T19:17:19.018400Z

yes, and that all applies to scheme, clojure is different, clojure is primarily concerned with seqs (clojure lists are seqs) which don't actually expose the cells that make them up

2021-01-26T19:19:06.019900Z

but having cons cells and improper lists (cells where the cdr is not a pair or nil) is useful in minikanren because you can represent a list where you haven't figured out what the rest of the list yet (the cdr is a logic var)

2021-01-26T19:19:26.020500Z

so core.logic has lcons to provide for that

michele mendel 2021-01-26T19:20:38.021500Z

I understand, but that makes pair a little odd in Clojure.

2021-01-26T19:20:57.021700Z

it is

2021-01-26T19:22:50.022700Z

pair doesn't really exist in the wider world of clojure, but exists in core.logic because The Reasoned Schemer is an important source of documentation for it, and examples in TRS need it

2021-01-28T11:41:03.025400Z

Yeah when I had a go at implementing microkanren, I found probably half the code of the complete implementation was just implementing scheme like linked lists in clojure.

2021-01-26T19:23:48.023700Z

well, really you'd need something like it even without the TRS to reason about lists, but the reason it is the way it is is because of TRS

michele mendel 2021-01-26T19:24:23.023900Z

Thanks