Didn't see anyone mention this little gem about Ruby:
a = [1,2,3]
x = :foo
puts x
a = a.map do |x|
x+1
endSee anything wrong here? (hint: what is the value of x?)
a = [1,2,3]
x = :foo
puts x
a = a.map do |x|
x+1
endSee anything wrong here? (hint: what is the value of x?)
irb(main):001:0> x = true or "hi"
=> true
irb(main):002:0> x
=> true
irb(main):003:0> x = false or "hi"
=> "hi"
irb(main):004:0> x
=> false
What? Short-circuit evaluation doesn't work in an assignment..? Oh. irb(main):005:0> x = (false or "hi")
=> "hi"
irb(main):006:0> x
=> "hi"
In fairness, the || operator does not require explicit parentheses — but I still hold that operator precedence is just evil.Spoiler alert:
.
.
.
1.8.x produces 3 while 1.9 produces :foo
Nuh-uh, not APL! That looks like line noise with no words mixed in. :-)