------art_18544_9995319.1205433133992
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Thanks. The output you report matches what I get in 1.8.6 and suggests where
to start looking for a bug. I'm not sure this is strictly related to blocks.
In particular try this:

x  .2*1 if
  x`1

The line break after the "if" is intentional since it more clearly shows
which part gets run when. In this code,
first there are two stops on the x`1 presumably before and after the
assignment. But by the time of the c-call to multiply 6.2*1, the value of x
is 6.1. It is like some sort of register flushing that is going before the
c-call, but again that's pure guess.

On Thu, Mar 13, 2008 at 12:59 PM, Yemi I. D. Bedu <yemi / weldfast.com> wrote:

>  Hello,
>
>  I tried this and it has to do with implicit / explicit block. Also I
> expanded example:
>
>
>
> p RUBY_VERSION
>
>
>
> def trace_func(event, file, line, id, binding, klass, *)
>
>   printf("%s:%d (%s) x\n", file, line, event, eval("x", binding))
>
> end
>
>
>
> set_trace_func method(:trace_func).to_proc
>
>
>
> x >
> (x02) if x01
>
> begin x@2 end if x@1
>
> xP2 if xP1
>
> x`2*1 if x`1*1
>
> if xp1 then xp2 end
>
> x
> x
>
>
> My Results were:
>
>
>
> "1.8.2"
>
>
>
> tt.rb:9 (line) x>
>
>
> tt.rb:10 (line) x >
> tt.rb:10 (line) x >
> tt.rb:10 (line) x01
>
>
>
> tt.rb:11 (line) x02
>
> tt.rb:11 (line) x02
>
> tt.rb:11 (line) x@1
>
>
>
> tt.rb:12 (line) x@2
>
> tt.rb:12 (line) x@2
>
>
>
> tt.rb:13 (line) xP2
>
> tt.rb:13 (line) xP2
>
> tt.rb:13 (c-call) xP2
>
> tt.rb:13 (c-return) xP2
>
> tt.rb:13 (c-call) x`1
>
> tt.rb:13 (c-return) x`1
>
>
>
> tt.rb:14 (line) x`2
>
> tt.rb:14 (line) x`2
>
> tt.rb:14 (line) xp1
>
>
>
> tt.rb:15 (line) xp2
>
>
>
> tt.rb:16 (line) x
>
>
> You would need to either have parens, explicit block or use the other if
> form to get that last firing from the trace. It seems to token out each
> expression unit on a line and then call eval to get the previous lines
> value. I don't know if you can confirm this on your 1.8.6 install. The
> lines with the multiply do func calls so they eval before going into the new
> env and when the come back. You might want to have a more complex expression
> execute like a list comprehension or a map. Good day.
>
> Yemi Bedu
>
> P&R Fasteners, Inc.
> P&R Castings, LLC.
> 325 Pierce St
> Somerset, NJ 08873
> (T) 732-302-3600
> (F) 732-302-3636
>   ------------------------------
>
> *From:* Rocky Bernstein [mailto:rocky.bernstein / gmail.com]
> *Sent:* Wednesday, March 12, 2008 11:21 PM
> *To:* ruby-core / ruby-lang.org
> *Subject:* Ruby 1.8.6 binding value after "if" expression evaluation
>
>
>
> 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\n", file, line, event, eval("x", binding))
> end
> set_trace_func method(:trace_func).to_proc
> xP> x`2 if x`1
> xp>
>
> $ ruby bug2.rb
> bug2.rb:6: warning: found  n conditional, should be > bug2.rb:5 (line) x> bug2.rb:6 (line) xP> bug2.rb:6 (line) xP> bug2.rb:7 (line) x`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`1) is evaluated and then called
> before the assignment "x`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
>

------art_18544_9995319.1205433133992
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Thanks. The output you report matches what I get in 1.8.6 and suggests where to start looking for a bug. I&#39;m not sure this is strictly related to blocks. In particular try this:<br><br>x  .2*1 if<br>&nbsp; x`1<br><br>The line break after the &quot;if&quot; is intentional since it more clearly shows which part gets run when. In this code,<br>
first there are two stops on the x`1 presumably before and after the assignment. But by the time of the c-call to multiply 6.2*1, the value of x is 6.1. It is like some sort of register flushing that is going before the c-call, but again that&#39;s pure guess.<br>
<br><div classmail_quote">On Thu, Mar 13, 2008 at 12:59 PM, Yemi I. D. Bedu &lt;<a hrefailto:yemi / weldfast.com">yemi / weldfast.com</a>&gt; wrote:<br><blockquote classmail_quote" styleorder-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">









<div linklue" vlinkurple" langホュユモ「セ

シセ

シセシ ont-size: 10pt; font-family: Arial; color: navy;">Hello,</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">&nbsp;I
tried this and it has to do with implicit / explicit block. Also I expanded
example:</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">&nbsp;</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">p
RUBY_VERSION</span></p><div classh2E3d">

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">&nbsp;</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">def
trace_func(event, file, line, id, binding, klass, *)</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">&nbsp;
printf(&quot;%s:%d (%s) x\n&quot;, file, line, event, eval(&quot;x&quot;,
binding))</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">end</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">&nbsp;</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">set_trace_func
method(:trace_func).to_proc</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">&nbsp;</span></p>

</div><p><span styleont-size: 10pt; font-family: Arial; color: navy;">x /span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">(x02)
if x01</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">begin
x@2 end if x@1</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">xP2
if xP1</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">x`2*1
if x`1*1</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">if
xp1 then xp2 end</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">xspan></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">xspan></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">&nbsp;</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">My
Results were:</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">&nbsp;</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">&quot;1.8.2&quot;</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">&nbsp;</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">tt.rb:9
(line) xspan></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">&nbsp;</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">tt.rb:10
(line) x /span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">tt.rb:10
(line) x /span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">tt.rb:10
(line) x01</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">&nbsp;</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">tt.rb:11
(line) x02</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">tt.rb:11
(line) x02</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">tt.rb:11
(line) x@1</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">&nbsp;</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">tt.rb:12
(line) x@2</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">tt.rb:12
(line) x@2</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">&nbsp;</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">tt.rb:13
(line) xP2</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">tt.rb:13
(line) xP2</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">tt.rb:13
(c-call) xP2</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">tt.rb:13
(c-return) xP2</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">tt.rb:13
(c-call) x`1</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">tt.rb:13
(c-return) x`1</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">&nbsp;</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">tt.rb:14
(line) x`2</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">tt.rb:14
(line) x`2</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">tt.rb:14
(line) xp1</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">&nbsp;</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">tt.rb:15
(line) xp2</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">&nbsp;</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">tt.rb:16
(line) xspan></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">&nbsp;</span></p>

<p><span styleont-size: 10pt; font-family: Arial; color: navy;">You
would need to either have parens, explicit block or use the other if form to
get that last firing from the trace. It seems to token out each expression unit
on a line and then call eval to get the previous lines value. I don't
know if you can confirm this on your 1.8.6 install. The lines with the multiply
do func calls so they eval before going into the new env and when the come back.
You might want to have a more complex expression execute like a list
comprehension or a map. Good day.</span></p>

<div>

<p><span styleont-size: 10pt; color: navy;">Yemi Bedu<br>
<br>
P&amp;R Fasteners, Inc.<br>
P&amp;R Castings, LLC.<br>
325 Pierce St<br>
Somerset, NJ 08873<br>
(T) 732-302-3600<br>
(F) 732-302-3636</span></p>

</div>

<div>

<div styleext-align: center;" align
enter"> <hr align
enter" size" width00%"> </div> <p><b><span styleont-size: 10pt; font-family: Tahoma;">From:</span></b><span styleont-size: 10pt; font-family: Tahoma;"> Rocky Bernstein [mailto:<a hrefailto:rocky.bernstein / gmail.com" targetblank">rocky.bernstein / gmail.com</a>] <br> <b>Sent:</b> Wednesday, March 12, 2008 11:21 PM<br> <b>To:</b> <a hrefailto:ruby-core / ruby-lang.org" targetblank">ruby-core / ruby-lang.org</a><br> <b>Subject:</b> Ruby 1.8.6 binding value after &quot;if&quot; expression evaluation</span></p> </div><div><div></div><div classj3C7c"> <p>&nbsp;</p> <p>Here&#39;s another trace hook weirdness that I&#39;ve encountered.<br> <br> Consider this program and its output:<br> <br> <span>def trace_func(event, file, line, id, binding, klass, *)<br> &nbsp; printf(&quot;%s:%d (%s) x\n&quot;, file, line, event, eval(&quot;x&quot;, binding))<br> end<br> set_trace_func method(:trace_func).to_proc<br> xPbr> x`2 if x`1<br> xpbr> <br> <br> $ ruby bug2.rb<br> bug2.rb:6: warning: found n conditional, should be br> bug2.rb:5 (line) x r> bug2.rb:6 (line) xPbr> bug2.rb:6 (line) xPbr> bug2.rb:7 (line) x`2<br> <br> </span><span styleont-family: Arial;">Why does x appear to have value 5 the second time on line 7 rather than 6.1? <br> <br> Looking at eval.c what&#39;s supposed to happen (I think) is that the trace hook is called before the expression (x`1) is evaluated and then called before the assignment &quot;x`2&quot; in which case it should have value 6.1, not 5.<br> <br> Can anyone explain why this happens? <br> <br> Again this is ruby 1.8.6 </span></p> </div></div></div> </div> </blockquote></div><br> ------art_18544_9995319.1205433133992--