You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The javascript driver is not constructing an invalid query, the ReQL api is being incorrectly used and the error message received is the expected error message given this incorrect usage. r.sub(1,2) is binary subtraction, equivalent 1 - 2. We don't currently support unary negation (i.e. -1) which is what @AtnNn appears to have been trying to do.
This issue should probably be named "ReQL Proposal: unary negation". Doing this would require a new ReQL term type (NEGATE probably) or overloading SUB to mean negation when given only 1 argument.
Regardless of which we choose, we can implement it in the JS driver side by overloading r.sub on 1 argument (question, do we want r.expr(1).sub() to do this?).
In Python and Ruby it will be a bit different because we have to overload the appropriate operator. In Python this would mean overloading __neg__.
One last thought, if we did add negation, how do we feel about adding r.abs for absolute value?
Unary is unfortunately not overloadable in python. I'm not sure about in ruby either. I'm a little bit dubious that r.sub(1) should return -1. I think it's a lot more likely that r.sub(1) is a typo than an attempt to negate a number and I'd like to leave the option open to have r.sub(1) be shorthand for lambda x: 1 - x in the future.
@jdoliner I do believe you can overload __neg__(self) in Python to implement this. Additionally, having r.sub(1) be shorthand for function(x) { return 1 - x} seems quite unintuitive to me. Still, I don't necessarily think we should support unary r.sub. The usefulness of this seems quite limited.
I think the current behavior is fine. We could probably debate this for a while and get the product to behave slightly better, but I think it would be in the realm of diminishing returns.
What does everyone else think? (I'd like to close this issue unless people feel strongly that we should fix this)
@wmrowan It appears you can overload __neg__ I'm not sure why we didn't do that.
Having r.sub(1) be shorthand for is probably unintuitive by itself but if we had currying in other places in the language it could wind up being really awesome. You could writing things like:
table.map({"foo" : r.sub(1), "bar" : r.add(1)})
anyways, this is outside of the scope of this discussion.
@coffeemug definitely close this. It's a nitty gritty issue that no real users have run in to and I see no reason to believe it's actually going to make things appreciably better.
Also, I think that even if real users end up running into this, it's the kind of feature where we can confidently say no. I don't think anyone would stop using the product because this is missing, and I feel like people would understand our rationale for not taking this on in the near future.
I realize I'm late to the party, but I think I agree with @AtnNn here.
We already support prefix negation in Ruby. We translate prefix minus of x to 0-x. I don't see any reason why we shouldn't support this behavior in Python as well; it's absurdly easy for us to do (literally one line in func.rb) and makes life slightly better for users.
I also think that we should strongly consider accepting 1-ary subtraction on the server. Every language I know of that offers n-ary subtraction (mostly just the lisps) accepts 1-ary subtraction. For instance, in Common Lisp, (- 2) gives -2.
The question for small issues like this isn't "will more people use the product if we do this", but "will more people use the product if we consistently take the time to get small issues like this right". I think the answer to the second one is an emphatic YES.
I'm gonna open up a separate ReQL proposal to debate whether to have 1-ary arithmetic operators, but leave it in backlog because I think we have more important ReQL problems in the 1.8 pipeline.
Activity
jdoliner commentedon Jul 18, 2013
This issue is just a story about something you did. Issues should be a clear description of a problem and what you think should be done to fix it.
AtnNn commentedon Jul 18, 2013
Thanks @jdoliner. I beleive the issue is that the javascript driver is constructing an invalid query and should be fixed.
neumino commentedon Jul 18, 2013
I may be wrong, but while
r.sub(1)could work in javascript,-r.expr(1)cannot work in Python and Ruby.wmrowan commentedon Jul 18, 2013
The javascript driver is not constructing an invalid query, the ReQL api is being incorrectly used and the error message received is the expected error message given this incorrect usage.
r.sub(1,2)is binary subtraction, equivalent1 - 2. We don't currently support unary negation (i.e.-1) which is what @AtnNn appears to have been trying to do.This issue should probably be named "ReQL Proposal: unary negation". Doing this would require a new ReQL term type (NEGATE probably) or overloading SUB to mean negation when given only 1 argument.
Regardless of which we choose, we can implement it in the JS driver side by overloading
r.subon 1 argument (question, do we wantr.expr(1).sub()to do this?).In Python and Ruby it will be a bit different because we have to overload the appropriate operator. In Python this would mean overloading
__neg__.One last thought, if we did add negation, how do we feel about adding
r.absfor absolute value?jdoliner commentedon Jul 18, 2013
Unary is unfortunately not overloadable in python. I'm not sure about in ruby either. I'm a little bit dubious that
r.sub(1)should return-1. I think it's a lot more likely thatr.sub(1)is a typo than an attempt to negate a number and I'd like to leave the option open to haver.sub(1)be shorthand forlambda x: 1 - xin the future.wmrowan commentedon Jul 18, 2013
@jdoliner I do believe you can overload
__neg__(self)in Python to implement this. Additionally, havingr.sub(1)be shorthand forfunction(x) { return 1 - x}seems quite unintuitive to me. Still, I don't necessarily think we should support unaryr.sub. The usefulness of this seems quite limited.coffeemug commentedon Jul 18, 2013
I think the current behavior is fine. We could probably debate this for a while and get the product to behave slightly better, but I think it would be in the realm of diminishing returns.
What does everyone else think? (I'd like to close this issue unless people feel strongly that we should fix this)
jdoliner commentedon Jul 18, 2013
@wmrowan It appears you can overload
__neg__I'm not sure why we didn't do that.Having
r.sub(1)be shorthand for is probably unintuitive by itself but if we had currying in other places in the language it could wind up being really awesome. You could writing things like:anyways, this is outside of the scope of this discussion.
@coffeemug definitely close this. It's a nitty gritty issue that no real users have run in to and I see no reason to believe it's actually going to make things appreciably better.
coffeemug commentedon Jul 18, 2013
Ok.
Also, I think that even if real users end up running into this, it's the kind of feature where we can confidently say no. I don't think anyone would stop using the product because this is missing, and I feel like people would understand our rationale for not taking this on in the near future.
Closing.
mlucy commentedon Jul 18, 2013
I realize I'm late to the party, but I think I agree with @AtnNn here.
We already support prefix negation in Ruby. We translate prefix minus of
xto0-x. I don't see any reason why we shouldn't support this behavior in Python as well; it's absurdly easy for us to do (literally one line infunc.rb) and makes life slightly better for users.I also think that we should strongly consider accepting 1-ary subtraction on the server. Every language I know of that offers n-ary subtraction (mostly just the lisps) accepts 1-ary subtraction. For instance, in Common Lisp,
(- 2)gives-2.The question for small issues like this isn't "will more people use the product if we do this", but "will more people use the product if we consistently take the time to get small issues like this right". I think the answer to the second one is an emphatic YES.
I'm gonna open up a separate ReQL proposal to debate whether to have 1-ary arithmetic operators, but leave it in backlog because I think we have more important ReQL problems in the 1.8 pipeline.