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

Adding number and string should work? #41

Closed
tcard opened this issue Feb 19, 2017 · 3 comments
Closed

Adding number and string should work? #41

tcard opened this issue Feb 19, 2017 · 3 comments

Comments

@tcard
Copy link

tcard commented Feb 19, 2017

According to 3.4.1:

If either operand of + is a string, then the other operand is converted to a string (if it isn’t already one) and the results are concatenated.

But both interpreter currently say:

Operands must be two numbers or two strings.

@egordorichev
Copy link

egordorichev commented Feb 19, 2017

I created a pull-request, that fixes that in clox #42

@munificent
Copy link
Owner

Oof, you're right! I wrote that chapter quite a while after implementing that behavior in Lox and I'm embarrassed to admit I misremembered how my own language works!

I think the simpler fix is to update the text to describe how Lox actually behaves. In a real language, it's probably more usable to convert either operand to a string, but doing that in Lox would add a decent amount of fairly boring code, so the simplest thing is to just leave it out and leave "+" a little less flexible.

I'll fix the prose.

@munificent
Copy link
Owner

Fixed by 0ba8c36.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants