←back to thread

317 points est | 1 comments | | HN request time: 0.234s | source
1. bluecalm ◴[] No.17453975[source]
This is badly needed equivalent of where keyword in Haskell very useful (among other things) in list comprehensions to avoid duplicating function calls (now you assign the result of the call and use it again in the beginning part of the comprehension).

That being said it's another example of how after many years it turns out that C got it right all along. Assignment being an expression (not a statement) makes many useful idioms possible. Sure, there was a problem with typos concerning '=' and '==' being similar but this was solved by convention of requiring parenthesis around assignment if its value is used as boolean. If you turn on warning in modern C compiler you will never make this error again. Interestingly it's also what Python has chosen even though they went with := operator.

Personally I prefer having one assignment operator and assignment being an expression. If it's := or = really doesn't matter in my view.