Brendan van der Es
2017-08-30 22:47:11 UTC
Hey all,
I'm trying to write a query that picks from a cardinality/many attribute
depending on the size of an input list. I'm looking at three different
input bindings to do this:
1. Can use collection binding to bind elements and create a clojure
wrapper (or alternatively, compose queries as
per https://groups.google.com/forum/#!topic/datomic/dexqK3QXiDM)
(defn wrapped-var-count
[L]
(d/q '[:find ?var ?var-count
:in [?var ...] ?var-count]
L (count L)))
I don't like this because it splits context of the query across a
technology boundary (Clojure <> Datalog); the datalog data structure on
it's own has an undesirable level of duplication and doesn't really
represent anything meaningful.
2. Can bind it as a data source.
(d/q '[:find ?var-el ?var-count
:in $var
:where
[(count $var) ?var-count]
[$var ?var-el]]
[[5] [6]])
This works fine but feels a little hacky to generalize a parameter to a
datasource and we have to conform to the list of list format of a data
structure
3. Would like to bind the input collection to a scalar variable and have a
second binding to the elements of the list. I currently have:
(d/q '[:find ?var-el ?var-count
:in ?var
:where [(count ?var) ?var-count]
[??? ?var ?var-el ???]]
[5 6])
Counting works just fine, but I can't figure out any way to access the
elements (besides putting in a bunch of clojure function clauses).
Is there a way to do a second binding to the elements? Or, is there a way
to treat a variable like a data source? Otherwise, what is the recommended
way to access an input as a list and as it's members in the : where clause
of a datalog statement?
Thanks.
I'm trying to write a query that picks from a cardinality/many attribute
depending on the size of an input list. I'm looking at three different
input bindings to do this:
1. Can use collection binding to bind elements and create a clojure
wrapper (or alternatively, compose queries as
per https://groups.google.com/forum/#!topic/datomic/dexqK3QXiDM)
(defn wrapped-var-count
[L]
(d/q '[:find ?var ?var-count
:in [?var ...] ?var-count]
L (count L)))
I don't like this because it splits context of the query across a
technology boundary (Clojure <> Datalog); the datalog data structure on
it's own has an undesirable level of duplication and doesn't really
represent anything meaningful.
2. Can bind it as a data source.
(d/q '[:find ?var-el ?var-count
:in $var
:where
[(count $var) ?var-count]
[$var ?var-el]]
[[5] [6]])
This works fine but feels a little hacky to generalize a parameter to a
datasource and we have to conform to the list of list format of a data
structure
3. Would like to bind the input collection to a scalar variable and have a
second binding to the elements of the list. I currently have:
(d/q '[:find ?var-el ?var-count
:in ?var
:where [(count ?var) ?var-count]
[??? ?var ?var-el ???]]
[5 6])
Counting works just fine, but I can't figure out any way to access the
elements (besides putting in a bunch of clojure function clauses).
Is there a way to do a second binding to the elements? Or, is there a way
to treat a variable like a data source? Otherwise, what is the recommended
way to access an input as a list and as it's members in the : where clause
of a datalog statement?
Thanks.
--
You received this message because you are subscribed to the Google Groups "Datomic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to datomic+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Datomic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to datomic+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.