Re: [wmii] dmenu mpd client

From: Suraj N. Kurapati <snk_AT_gna.org>
Date: Mon, 15 Oct 2007 14:46:15 -0700 (PDT)

Johannes Krude wrote:
> Christian G. Warden schrieb:
>> +$dmenu= ENV["DMENU"] || "dmenu -b"
>
> This is in ruby exactly the same, I think "or" is
> more readable then "||"

I agree that 'or' is more readable than '||' but keep
in mind that the '||' and 'or' operators are
*different* in terms of precedence. Take a look at
this precedence table:

http://www.zenspider.com/Languages/Ruby/QuickRef.html#22

Notice that 'and' and 'or' have the lowest precedence
(even lower than '=') than all other operators. As a
result, that statement is evaluated like this:

  $dmenu= ENV["DMENU"]

is the result of the above expression nil or false?
If so, evaluate the stuff on the right-hand side of
the 'or':

  "dmenu -b"

And use this as the result of the overall expression
(the entire line). So, if there is no $DMENU
environment variable, then nothing gets assigned to
the $dmenu global(!) variable.

To illustrate, consider this example:

>> x = nil or 5
=> 5
>> x
=> nil

Notice that the value of 'x' is NOT 5. If you used
the '||' operator instead, then you get:

>> x = nil || 5
=> 5
>> x
=> 5

So the moral of the story is: stick with the C-style
boolean operators unless you really intend to do
something else.
Received on Mon Oct 15 2007 - 23:46:47 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 16:30:00 UTC