core-logic

2018-06-14T13:11:07.000147Z

Is it possible to define a lookup relation for map keys, similar to (geto k m v) ? I saw that maps unify only over values, so this might be hard.

2018-06-14T21:43:26.000577Z

Okay,

(defn geto [m k v]
  (featurec m {k v}))
Seems to do the trick, at least when k really is a keyword. I don't understand why it's limited to values though

2018-06-14T21:55:49.000145Z

it is very tricky

2018-06-14T21:56:24.000437Z

if k is a key in m, and v is a value in m, and q unifies with m, what values does q have?

2018-06-14T21:57:32.000274Z

(values in the sense of, what are the possible values of q)

2018-06-14T21:57:58.000434Z

Hmm, I'd assume all values that (featurec m {k v}) produces? 😉

2018-06-14T21:58:35.000325Z

it is trivial to determine the values when keys are ground

2018-06-14T21:58:57.000182Z

What do you mean by ground?

2018-06-14T21:59:06.000444Z

a concrete value

2018-06-14T21:59:17.000327Z

a known keyword

2018-06-14T21:59:25.000029Z

Ok

2018-06-14T21:59:32.000399Z

(as opposed to a logic variable with an unknown value)

2018-06-14T21:59:47.000458Z

Yeah, got it

2018-06-14T22:00:20.000383Z

basically you can't use just a clojure map to represent that

2018-06-14T22:00:52.000181Z

you need some more complicated datastructure that understands unification and can do things like merge keys that are unified

2018-06-14T22:01:25.000205Z

like if you say (get m k v) (get m y x) (== y k)

2018-06-14T22:01:40.000035Z

uh, geto

2018-06-14T22:01:47.000239Z

Hm, so it would be possible, but only if I converted my maps to that richer datastructure before?

2018-06-14T22:02:12.000002Z

And I'd have to make it extend the unification protocol?

2018-06-14T22:02:20.000031Z

I am not sure

2018-06-14T22:03:52.000081Z

I feel like I was reading a paper on unifying maps recently

2018-06-14T22:04:29.000143Z

Really? Nice coincidence then 🙂

2018-06-14T22:04:30.000105Z

oh, no, it was clp(set)

2018-06-14T22:04:38.000360Z

Ah, ok

2018-06-14T22:04:40.000521Z

but I think that would be really similar

2018-06-14T22:04:56.000173Z

e.g. you would represent the map as a set of k/v pairs

2018-06-14T22:05:54.000116Z

there is a scheme implementation somewhere that needs porting

2018-06-14T22:06:31.000450Z

Hm yeah, it looks like this would do it, if it were implemented, which it doesn't seem to be 😄

2018-06-14T22:06:38.000048Z

https://github.com/namin/clpset-miniKanren

2018-06-14T22:06:54.000025Z

(the link to the paper is in the readme on that repo)

2018-06-14T22:08:45.000016Z

Hm, that looks more like a weekend-y kind of thing 😉

2018-06-14T22:09:21.000155Z

I wouldn't mind a simpler way to achieve my goal, which is basically have an interpreter for a very simple language

2018-06-14T22:10:16.000005Z

I think the scheme guys just use a list of pairs

2018-06-14T22:10:36.000319Z

Yeah, that might be the way to go for now

2018-06-14T22:11:43.000238Z

Thanks, I'll try that

2018-06-14T22:11:57.000043Z

Also read the paper when I have a moment, which might be a while 😉