clojure - Why (= (run 1 [q] (membero 'cat q)) ['(cat . _.0)]) is false? -


i'm doing clojure/core.logic koans , stuck on this one:

"here give run specific number control how many answers get. think carefully. there 1 list in universe satisfies relation? there infinitely many?"  (= (run 1 [q]        (membero 'cat q))     [__]) 

running (run 1 [q] (membero 'cat q)) in repl said me answer ((cat . _.0)). i'm not quite sure dot in middle means, anyway, sticking '(cat . _.0) instead of __ placeholder in original koan doesn't (assertion still fails). please point me right direction? , explain dot between cat , _.0 means? guess means what follows (i.e. _.0) tail of length, i'm not 100% sure. === update

amalloy pointed me right direction (thank you, sir!). lcons trick:

 (= (run 1 [q]        (membero 'cat q))     [(lcons 'cat '_.0)]) 

and bit of repl:

user=> (lcons 'cat '_.0) (cat . _.0) user=> '(cat . _.0) (cat . _.0) user=> (= '(cat . _.0) (lcons 'cat '_.0)) false 

the dot used represent, well, dotted lists. according wikipedia, dotted list kind of improper lists, kind circular list. so, in repl session above, first list dotted list 2 elements ('cat , '_.0), whereas second list proper list 3 elements ('cat', '. , '._0). string representation same, nevertheless different.

the (a . b) notation carryover other lisps use cons cells build improper lists. correct means "the symbol cat followed list of length", it's printed representation of core.logic lcons value. there's no easy literal can type produce value of type, can't comparisons against values of own. however, expect lcons seqable, compare (first the-thing) 'cat, , on.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -