datascript

grumplet 2022-01-07T10:14:03.002200Z

Would anyone here have any pointers as to the best way to interop with R. I have a cljs implementation of an R coxph model and I need to write a coverage test that checks the cljs against the R code?

refset 2022-01-07T18:37:00.004200Z

Hey, I have no idea what would actually work best in your situation, but I did just discover this possibility of calling graaljs (e.g. using compiled cljs) from this Truffle-based R-Graal implementation: https://github.com/oracle/fastr/blob/1ce6f36bec5c5f8520ab0f0f330f9dee23ed7c55/documentation/user/Interoperability.md Out of interest, are you using DataScript in the cljs as the underlying engine for the regression model? Or is it just one part of the picture?

zane 2022-01-08T16:24:19.016700Z

You could also consider, as a first pass, avoiding interop entirely. Might not be worth it. Could either shell out to R from CLJS or have separate R and CLJS programs that write the results of the test expressions to disk and then have a third program examine and compare the results.

✔️ 1
➕ 1
2022-01-07T18:08:42.004100Z

hello! I’m trying to load in a serialized db using the JS API and can’t get it to work. I have the database in EDN format. I’ve tried several things, but this is the latest:

let ds = require('datascript');
let edn = require('jsedn');

let d = require('fs').readFileSync('./persona.edn', 'utf8');
let data = edn.parse(d);

let conn = ds.conn_from_datoms(
  edn.toJS(edn.atPath(data, ':datoms')),
  edn.toJS(edn.atPath(data, ':schema'))
);

let query = '[:find ?id :where [?b :block/uid ?id]]';
let result = ds.q(query, conn);

console.log(result);
conn is created fine but when running the query I get [object Object] is not ISeqable. Looking at the code, it doesn’t seem to run js->clj on the value of the datom, is that the problem? I can’t find any examples for doing this through JS

lilactown 2022-01-07T18:38:13.004500Z

i think you need to get the current db from the conn

lilactown 2022-01-07T18:38:44.004700Z

let result = ds.q(query, ds.db(conn));

lilactown 2022-01-07T18:40:43.005100Z

translated to clojure:

(def result (ds/q query @conn))

2022-01-07T18:44:08.005300Z

nice! that does get a lot closer

2022-01-07T18:45:06.005500Z

it runs but the query errors with Cannot compare :block/parents to :block/refs. I know this might be specific to my db, but that query works from the place I exported the db from. I’m not referencing :block/parents at all — any ideas where I should look?

2022-01-07T18:46:44.005700Z

might be the schema

lilactown 2022-01-07T19:11:03.005900Z

i'm getting similar errors with pretty basic data/schema

lilactown 2022-01-07T19:12:56.006100Z

it works when i use string keys

lilactown 2022-01-07T19:13:18.006300Z

let ds = require('datascript');
let edn = require('jsedn');

let d = require('fs').readFileSync('./persona.edn', 'utf8');
let data = edn.parse(d);

// let schema = edn.toJS(edn.atPath(data, ':schema'));
let schema = {"person/id": {":db/unique": ":db.unique/identity"}};

//let datoms = edn.toJS(edn.atPath(data, ':datoms'));
let datoms = [[1, "person/id", 1],
              [1, "person/name", "Will"]];

let conn = ds.conn_from_datoms(
    datoms, schema
);

let query = '[:find ?v :where [?p "person/id" ?v]]';
let result = ds.q(query, ds.db(conn));

console.log(result);

lilactown 2022-01-07T19:18:31.006500Z

hmm i see. datascript does not convert strings to keywords other than ds-specific strings like :db/id and schema definition keywords

lilactown 2022-01-07T19:19:16.006700Z

jsedn toJS stringifies keywords.

lilactown 2022-01-07T19:22:37.006900Z

so you'll need to wrap your keyword attrs you're loading from disk in quotes in your query

lilactown 2022-01-07T19:23:01.007100Z

i.e.

let query = '[:find ?id :where [?b ":block/uid" ?id]]';

lilactown 2022-01-07T19:23:58.007300Z

not the nicest but unless you're going to read the EDN in as actual CLJS data yourself that might be as good as you get

lilactown 2022-01-07T19:24:49.007600Z

also not sure what will happen if you try and round trip the db, i.e. make changes to the db and then write it back out to disk

2022-01-07T19:40:01.007800Z

very nice that works, thank you!

2022-01-07T19:40:09.008Z

I don’t need changes, my project is just read-only for this 🙂

2022-01-07T19:46:41.008200Z

is there any other way to provide a query? I’m confused about this writeup: https://github.com/kristianmandrup/datascript-tutorial/blob/master/javascript_api.md#jsedn-converter

2022-01-07T19:46:44.008500Z

is that old?

lilactown 2022-01-07T20:11:00.008800Z

I think the key their is they're parsing the query string using edn.parse

lilactown 2022-01-07T20:12:41.009100Z

so that turns it into JS data. then datascript reads that JS data, and treats the attributes it finds as strings

lilactown 2022-01-07T20:16:56.009300Z

so in your case that would work well because you're parsing the datums into JS objs and then you could parse the query string as well

2022-01-07T20:19:32.009500Z

yeah, thanks! I’ve tried it though and something is weird. why do that pass query as an array? d.q([query], …)

2022-01-07T20:20:11.009700Z

I’ve tried let result = ds.q(edn.parse(query), ds.db(conn)); which gives No protocol method ICounted.-count defined

2022-01-07T20:20:34.009900Z

and if I wrap it in an array, this.ja.charAt is not a function

lilactown 2022-01-07T20:20:37.010100Z

yeah that is weird. if you note in that example they do not wrap the query string in a vector, it's just kws and variables

lilactown 2022-01-07T20:21:09.010800Z

maybe that example is just out of date

2022-01-07T20:21:31.011Z

it’s from 2016, so likely