docs icon indicating copy to clipboard operation
docs copied to clipboard

Writing RethinkDB Drivers has incorrect AST example for `r.do`

Open robertjpayne opened this issue 9 years ago • 4 comments

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.

robertjpayne avatar Sep 14 '16 15:09 robertjpayne

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 ] ]

robertjpayne avatar Sep 14 '16 16:09 robertjpayne

Good catch, thanks for reporting it @robertjpayne . So we just need to add the extra ] at the end, right?

danielmewes avatar Sep 14 '16 18:09 danielmewes

@danielmewes yup!

robertjpayne avatar Oct 02 '16 11:10 robertjpayne

@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?

robertjpayne avatar Oct 02 '16 11:10 robertjpayne