Hacker News new | past | comments | ask | show | jobs | submit login

'2+34' is unambiguously different from '43+2' (the former evaluates to 14 while the latter is 24)

I really hope the markdown has mangled this.




Me too. I'm trying to decipher what was typed, and not sure if I get it right. I'll try with spaces.

So, 2 + 3 * 4 is indeed 14 in J. The reason is J does calculations from right to left, so first 3 is multiplied to 4 making 12 and then 2 is added to that making 14.

The expression 4 * 3 + 2 would evaluate in J to 20 - not to 24. That's because first 3 + 2 makes 5 and then 4 * 5 makes 20. All verbs in J are of equal priority and evaluated right to left - no exceptions for arithmetical + - * % they are all equal and only right to left order matters.

May be I got it wrong and it wasn't 2 + 3 * 4 versus 4 * 3 + 2 but something else which would make 14 and 24 as results. But may be it's just a typo.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: