docs
docs copied to clipboard
Writing RethinkDB Drivers has incorrect AST example for `r.do`
The docs currently show:
[FUNCALL,
[FUNC,
[[MAKE_ARRAY, [1, 2]],
[ADD,
[[VAR, [1]],
[VAR, [2]]]]]],
10,
20]
// FUNCALL = 64, FUNC = 69, MAKE_ARRAY = 2, ADD = 24, VAR = 10
[64, [69, [[2, [1, 2]], [24, [[10, [1]], [10, [2]]]]]], 10, 20]
I believe it is incorrect and should instead read:
[FUNCALL,
[[FUNC,
[[MAKE_ARRAY, [1, 2]],
[ADD,
[[VAR, [1]],
[VAR, [2]]]]]],
10,
20]
]
// FUNCALL = 64, FUNC = 69, MAKE_ARRAY = 2, ADD = 24, VAR = 10
[64, [[69, [[2, [1, 2]], [24, [[10, [1]], [10, [2]]]]]], 10, 20]]
There is a missing [ before FUNC and at the end there is a missing ]. I think it may be valid REQL to have both of these brackets emitted but it's confusing when the node.js driver does emit these.
I've confirmed this syntax with the RethinkDB Dash JavaScript driver:
var r = require("rethinkdbdash")();
var q = r.do(10, 20, function (x, y) {
return r.add(x, y);
})
console.dir(q._query, { depth: null });
Which outputs:
[ 64,
[ [ 69,
[ [ 2, [ 1, 2 ] ], [ 24, [ [ 10, [ 1 ] ], [ 10, [ 2 ] ] ] ] ] ],
10,
20 ] ]
Good catch, thanks for reporting it @robertjpayne . So we just need to add the extra ] at the end, right?
@danielmewes yup!
@danielmewes actually there are two weird errors:
There is a missing [ before FUNC it should have two, and there is also a missing ] at the end. I guess it's "valid" syntax to drop these but since the node.js driver emits them and most clients will pair them into a datum array I figure the docs should reflect that?