Ruby block and unparenthesized arguments

It’s because you’re calling pp x.map and passing a block to pp (which ignores it) As explained in the Programming Ruby book Braces have a high precedence; do has a low precedence So, effectively, braces tie to the function call closest to them (x.map) whereas do binds to the furthest away (pp). That’s a bit … Read more

What is the formal difference in Scala between braces and parentheses, and when should they be used?

I tried once to write about this, but I gave up in the end, as the rules are somewhat diffuse. Basically, you’ll have to get the hang of it. Perhaps it is best to concentrate on where curly braces and parenthesis can be used interchangeably: when passing parameters to method calls. You may replace parenthesis … Read more

The need for parentheses in macros in C [duplicate]

Consider the macro replacement using this macro: #define SQR(x) (x*x) Using b+5 as the argument. Do the replacement yourself. In your code, SQR(b+5) will become: (b+5*b+5), or (3+5*3+5). Now remember your operator precedence rules: * before +. So this is evaluated as: (3+15+5), or 23. The second version of the macro: #define SQR(x) ((x) * … Read more