# Clarify on PHP operators precedence ! and =

I was happy coding until I wrote a code like this (in PHP 8.2): if (!\$a = false) { echo ‘\$a is false’; } This snippet will print \$a is false as expected. But according to the PHP documentation, the ! operator has greater precedence over the = operator, so that should be interpreted as… Read More Clarify on PHP operators precedence ! and =

# Haskell – priority of operations

I’m trying to be clear with the precedence rules in Haskell. When I write the line of code "f a b" it will be interpreted (f a) b ie with a left-associative mechanism. But let’s imagine that I am coding in Haskell a function calculating the terms of the fibonnaci sequence. I then run the… Read More Haskell – priority of operations

# Why does && operator not work inside a hash block but and operator does?

Given the following hash hash = {a: 5, b: 10} I want to check if all values are Integers and < 10. hash.all?{|key,value| value.is_a? Integer && value < 10} ## TypeError: class or module required from (pry):3:in `is_a?’ hash.all?{|key,value| value.is_a? Integer and value < 10} ## false Why does the first example with the &&… Read More Why does && operator not work inside a hash block but and operator does?

# Which expression has priority in `v[–i] = 100;`? the subscripting or the unary expression

This is more of a fundamental question rather than a useful one but here it goes. According to the C++ standard, postfix expressions (e.g., v[i]), have priority over unary expressions (e.g., –i). Therefore, I was wondering what is the actual sequence of steps that a program follows to implement this statement v[–i] = 100;. std::vector<int>… Read More Which expression has priority in `v[–i] = 100;`? the subscripting or the unary expression

# Operator precedence for logical AND (&& )and logical OR (||)

As per the operator precedence table for JavaScript, I can see that && has higher precedence than ||. So, for the following code snippet: let x, y; let z = 5 || (x = false) && (y = true); console.log(z); // 5 console.log(x); // undefined console.log(y); // undefined I thought that && should be evaluated… Read More Operator precedence for logical AND (&& )and logical OR (||)

# CMake evaluation of compound condition

The CMake documentation states: The following syntax applies to the condition argument of the if, elseif and while() clauses. Compound conditions are evaluated in the following order of precedence: Innermost parentheses are evaluated first. Next come unary tests such as EXISTS, COMMAND, and DEFINED. Then binary tests such as EQUAL, LESS, LESS_EQUAL, GREATER, GREATER_EQUAL, STREQUAL,… Read More CMake evaluation of compound condition

# Kotlin – Is it possible to check for operator precedence

Let’s say I have the following class: data class Foo(var name: String) { operator fun plus(foo: Foo): Foo { name += foo.name return this } } Which is then used like this: val foo1 = Foo("1") val foo2 = Foo("2") val foo3 = Foo("3") foo1+foo2+foo3 println(foo1.name) // 123 Now, what if I wanted different behavior… Read More Kotlin – Is it possible to check for operator precedence