associativity

What is associativity of operators and why is it important?

What is associativity (for an operator) and why is it important? Updated: operator associativity ...

C# conditional AND (&&) OR (||) precedence

We get into unnecessary coding arguments at my work all-the-time. Today I asked if conditional AND (&&) or OR (||) had higher precedence. One of my coworkers insisted that they had the same precedence, I had doubts, so I looked it up. According to MSDN AND (&&) has higher precedence than OR (||). But, can you prove it to a skeptical co...

How does Perl decide which order to evaluate terms in an expression?

Given the code: my $x = 1; $x = $x * 5 * ($x += 5); I would expect $x to be 180: $x = $x * 5 * ($x += 5); #$x = 1 $x = $x * 5 * 6; #$x = 6 $x = 30 * 6; $x = 180; 180; But instead it is 30; however, if I change the ordering of the terms: $x = ($x += 5) * $x * 5; I do get 180. The reason I am confused is that perldoc per...

Ternary operator associativity in C# - can I rely on it?

Ahh, don't you just love a good ternary abuse? :) Consider the following expression: true ? true : true ? false : false For those of you who are now utterly perplexed, I can tell you that this evaluates to true. In other words, it's equivalent to this: true ? true : (true ? false : false) But is this reliable? Can I be certain that...

Operator associativity in C specifically prefix and postfix increment and decrement

In C operation associativity is as such for increment, decrement and assignment. 2. postfix ++ and -- 3. prefix ++ and -- 16. Direct assignment = The full list is found here Wikipedia Operators in C My question is when we have int a, b; b = 1; a = b++; printf("%d", a); // a is equal to 1 b = 1; a = ++b; printf("%d", a)...

How does the different behavior of the unless- and "if !" statement influence the range-operator in scalar context?

Hello! On http://sial.org/howto/perl/one-liner/ I found the following two one-liners. The outputs are different because the unless statement is different from if ! ( due to the associativity and precedence rules ). cat file: foo bar perl -ne 'print unless /^$/../^$/' file foo bar perl -ne 'print if ! /^$/../^$/' fi...

Why isn't `"repeat" * 3` the same as `3 * "repeat"` in Ruby?

When I type this: puts 'repeat' * 3 I get: >> repeat repeat repeat But it's not working if I do this: puts 3 * 'repeat' Why? ...

Associativity in Lambda calculus

Hi All, I am working on the exercise questions of book The Lambda calculus. One of the questions that I am stuck is proving the following: Show that the application is not associative; in fact, x(yz) not equals (xy)z Here is what I have worked on so far: Let x = λa.λb. ab Let y = λb.λc. bc Let z = λa.λc. ac (xy)z => ((λa.λb. ab) (λb....

What does this PHP function return?

Hi. public function add($child){ return $this->children[]=$child; } Btw, this is an excerpt from PHP in Action by Dagfinn Reiersol. According to the book, this returns $child, but shouldn't it return true in case of successful assignment and false otherwise? Thanks in advance ...

Why do different operators have different associativity?

I've got to the section on operators in The Ruby Programming Language, and it's made me think about operator associativity. This isn't a Ruby question by the way - it applies to all languages. I know that operators have to associate one way or the other, and I can see why in some cases one way would be preferable to the other, but I'm s...