Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using .add() with a string and a number, automatically coerce the number to string #3800

Closed
thelinuxlich opened this issue Feb 19, 2015 · 13 comments

Comments

@thelinuxlich
Copy link

r(1).add("1") // "11", like JS behavior

or have a special method .concat()?

@danielmewes
Copy link
Member

This sounds very reasonable to me. We will include this in the next RQL_proposal discussion period.

@danielmewes danielmewes modified the milestones: backlog, subsequent, 2.1, 2.1-polish Mar 23, 2015
@coffeemug
Copy link
Contributor

I personally don't think it's a good idea. For example, should the value here be 2 or 11? What about r('1').add(1)?

I think people should coerce types explicitly.

@deontologician
Copy link
Contributor

I think coercion of numbers to strings in javascript is a huge mis-feature that we shouldn't replicate. Having a string formatting term would be better in my opinion

@mlucy
Copy link
Member

mlucy commented Apr 22, 2015

I don't think we should do this, personally. I second what @deontologician said about adding a string formatting command.

@danielmewes
Copy link
Member

Ok I can see that supporting this can be dangerous.
I think having a special concat term would be reasonable generally, but on the other hand the difference between that term and add would be difficult to explain since it's so small. So in the end I think that would be a bad idea as well.

I don't understand how a string formatting term is related to this though? You can already coerce the number to a string.

@deontologician
Copy link
Contributor

Because usually the reason you'd want to take advantage of auto-coercion is in code like:

r.expr("I have").add(x).add(" cookies and ").add(y).add(" brownies")

where coercions would be really verbose. (Though without overloaded operators in js, it's pretty verbose even with auto-coercion.)

@deontologician
Copy link
Contributor

something like:

r.format("I have {} cookies and {} brownies", x, y)

would be much nicer

@danielmewes
Copy link
Member

I see, thanks for explaining.
@thelinuxlich is the use case you had for this originally something that would be addressed by a format term?

@deontologician
Copy link
Contributor

For posterity, #3353 is the string formatting issue

@thelinuxlich
Copy link
Author

Yes, r.format would be nice!

@mlucy
Copy link
Member

mlucy commented Apr 24, 2015

@danielmewes, could we close this in favor of #3353?

@danielmewes
Copy link
Member

I'd like to wait until the end of the ReQL discussion period on Monday. I'll close it then.

@danielmewes
Copy link
Member

Closing. We'll later implement a formatting term instead.

@danielmewes danielmewes modified the milestones: wontfix, 2.1-polish Apr 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants