From: Rocky Bernstein Date: 2008-03-13T12:21:24+09:00 Subject: Ruby 1.8.6 binding value after "if" expression evaluation ------=_Part_14537_13822577.1205378493760 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Here's another trace hook weirdness that I've encountered. Consider this program and its output: def trace_func(event, file, line, id, binding, klass, *) printf("%s:%d (%s) x=%s\n", file, line, event, eval("x", binding)) end set_trace_func method(:trace_func).to_proc x=5 x=6.2 if x=6.1 x=7 $ ruby bug2.rb bug2.rb:6: warning: found = in conditional, should be == bug2.rb:5 (line) x= bug2.rb:6 (line) x=5 bug2.rb:6 (line) x=5 bug2.rb:7 (line) x=6.2 Why does x appear to have value 5 the second time on line 7 rather than 6.1? Looking at eval.c what's supposed to happen (I think) is that the trace hook is called before the expression (x=6.1) is evaluated and then called before the assignment "x=6.2" in which case it should have value 6.1, not 5. Can anyone explain why this happens? Again this is ruby 1.8.6 ------=_Part_14537_13822577.1205378493760 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Here's another trace hook weirdness that I've encountered.

Consider this program and its output:

def trace_func(event, file, line, id, binding, klass, *)
  printf("%s:%d (%s) x=%s\n", file, line, event, eval("x", binding))
end
set_trace_func method(:trace_func).to_proc
x=5
x=6.2 if x=6.1
x=7


$ ruby bug2.rb
bug2.rb:6: warning: found = in conditional, should be ==
bug2.rb:5 (line) x=
bug2.rb:6 (line) x=5
bug2.rb:6 (line) x=5
bug2.rb:7 (line) x=6.2

Why does x appear to have value 5 the second time on line 7 rather than 6.1?

Looking at eval.c what's supposed to happen (I think) is that the trace hook is called before the expression (x=6.1) is evaluated and then called before the assignment "x=6.2" in which case it should have value 6.1, not 5.

Can anyone explain why this happens?

Again this is ruby 1.8.6
------=_Part_14537_13822577.1205378493760--