Datomic query support

57 views
Skip to first unread message

Matt Bossenbroek

unread,
Jun 8, 2017, 12:30:07 AM6/8/17
to cur...@googlegroups.com
Have you considered adding support for query variables in a datomic query? Something that could identify unused or mismatched bindings, similar to the support in normal functions.

Currently since all query vars start with a ?, I get no autocomplete either & end up misspelling a lot of them.

Let me know if you’re interested & I could provide some samples of what it could do.

Thanks,
Matt

Colin Fleming

unread,
Jun 8, 2017, 12:31:30 AM6/8/17
to cur...@googlegroups.com

Yes, I have, but samples for this would be great, thanks!

--
You received this message because you are subscribed to the Google Groups "Cursive" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cursive+u...@googlegroups.com.
To post to this group, send email to cur...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cursive/CAHj4K5o4F8sxWaWGt3ySHs6D_F79Fifcje%3DEDomr-RE3vFGo5Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Matt Bossenbroek

unread,
Jun 8, 2017, 12:46:27 AM6/8/17
to cur...@googlegroups.com, Colin Fleming
Awesome - that was quick :)

Here’s an example buggy query:

(d/q '{:find [?barr ?qux]
:in [$ ?foo]
:where [[?foo :foo/bar ?bar]
[?bar :bar/baz ?baz]]}
db)

We could catch the following:

1) ?barr isn’t present in the query (misspelled)
2) ?qux isn’t there either (made up). Really just all :find vars need to be in the query
3) We’ll get an arity exception because we defined an extra param (?foo) but didn’t provide it.
4) ?baz isn’t used

You could also look for vars provided in the :in clause, but not actually used.

I’m not sure if it would be an error for one of the ?bar’s in the query itself to be misspelled as it would provide a disjoint query. Maybe a simple heuristic that every var must appear more than once - otherwise it could be eliminated. That would catch quite a number of misspellings & semantic errors as well.

Also, datomic has a well defined query grammar. Anything that doesn’t match this could be flagged with an inspection rule: http://docs.datomic.com/query.html#sec-4-2


Thanks!

-Matt

Colin Fleming

unread,
Jun 8, 2017, 5:29:32 AM6/8/17
to Matt Bossenbroek, cur...@googlegroups.com

One question - how common is it to compose queries from sub-parts in separate data structures?

Matt Bossenbroek

unread,
Jun 8, 2017, 10:10:12 AM6/8/17
to Colin Fleming, cur...@googlegroups.com
I never use it. I always felt like it was too confusing & generated queries that were impossible to profile.

That doesn’t mean that other people don’t though

-Matt

Matt Bossenbroek

unread,
Jun 8, 2017, 10:24:40 AM6/8/17
to Colin Fleming, cur...@googlegroups.com
Oooh - and rename refactoring support :)

Currently it just renames the highlighted symbol.

Thanks!

-Matt

Timothy Baldridge

unread,
Jun 8, 2017, 10:36:24 AM6/8/17
to cur...@googlegroups.com
Composing queries on-the-fly is discouraged in Datomic, mostly because the engine will do some amount of query pre-processing and caching, so the proper form is:

(q '[... static query form...]
   db param1 param2 ...)

But some sort of semi-generic system for renaming symbols inside quoted forms seems like a nice-to-have feature. 

Timothy

To unsubscribe from this group and stop receiving emails from it, send an email to cursive+unsubscribe@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Cursive" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cursive+unsubscribe@googlegroups.com.

To post to this group, send email to cur...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cursive/etPan.5938d31d.4d0078fb.18b6%40cursive-ide.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Cursive" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cursive+unsubscribe@googlegroups.com.

To post to this group, send email to cur...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
“One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.”
(Robert Firth)

Mark Addleman

unread,
Jun 8, 2017, 1:01:00 PM6/8/17
to Cursive, mbosse...@netflix.com, cur...@cursive-ide.com
Tossing in a tangential 2 cents:  core.logic macros have a vaguely similar syntax as Datomic queries and suffer from the very similar pain when working with Cursive

Timothy Baldridge

unread,
Jun 8, 2017, 1:05:17 PM6/8/17
to cur...@googlegroups.com
Really it's a problem with any macro that defines new symbols. 

(defmacro foo [bindings & body]
  `(let ~bindings ~@body))

(foo [x 42]
  x)

That's valid clojure, but x shows up as undefined in Cursive. 

That's probably the real problem to solve here, some way for users to hint to Cursive that a symbol in a certain position of a form is creating a new symbol that is valid for the body. 

This case is simple since the structure is the same as `let`, but as mentioned core.logic has fresh:

(fresh [x]
  ...)

To unsubscribe from this group and stop receiving emails from it, send an email to cursive+unsubscribe@googlegroups.com.

To post to this group, send email to cur...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Colin Fleming

unread,
Jun 8, 2017, 3:43:09 PM6/8/17
to cur...@googlegroups.com

Thanks Timothy, that’s good to know. That makes this easier.

To unsubscribe from this group and stop receiving emails from it, send an email to cursive+u...@googlegroups.com.

To post to this group, send email to cur...@googlegroups.com.

Colin Fleming

unread,
Jun 8, 2017, 3:48:04 PM6/8/17
to cur...@googlegroups.com

Right, Cursive will now let you say “this macro resolves like let” (see here). I’m planning to extend the UI to allow any form to be resolved like any other - currently you can achieve that by hacking config files, but it’s not optimal.

I also have a long-term plan to have an API that will allow anyone to contribute support for these forms, but it’s proving elusive.

Reply all
Reply to author
Forward
0 new messages