IF statement in ruby 1.8.0 (2003-05-26) [i386-mswin32] 
Author Message
 IF statement in ruby 1.8.0 (2003-05-26) [i386-mswin32]

Just when I thought that I had perfectly understood the IF statement in
Ruby, I had this humbling revelation:
(line numbers for reference only)
#----------------------------------------------------------------
01: set_trace_func proc{|event, file, line, objId, binding, klass|
02:                                           p [file,line] if(event ==
'line')  }
03:
04: a = 0 #<---- Remove this 0
05:    if
06:    true
07:      puts 'here'
08:      10
09:    else
10:      puts 'there'
11:      20
12:    end
13:
14: p a
15:
16: set_trace_func(nil)
#-----------------------------------------------------------------

This produces:

    ["C:/atest/tst_set_trace.rb", 4]
    ["C:/atest/tst_set_trace.rb", 6]     <<< This is ok...
    ["C:/atest/tst_set_trace.rb", 6]     <<<  But why this ?
    ["C:/atest/tst_set_trace.rb", 7]
    here
    ["C:/atest/tst_set_trace.rb", 8]
    ["C:/atest/tst_set_trace.rb", 14]
    0
    ["C:/atest/tst_set_trace.rb", 16]

Notice the line 6 traced twice ??
And now remove the 0 (just the constant, not the 'a = ' ) on line 4
to get:

    ["C:/atest/tst_set_trace.rb", 4]
    ["C:/atest/tst_set_trace.rb", 6]
    ["C:/atest/tst_set_trace.rb", 7]
    here
    ["C:/atest/tst_set_trace.rb", 8]
    ["C:/atest/tst_set_trace.rb", 14]
    10
    ["C:/atest/tst_set_trace.rb", 16]

which is what I expected in the first place.

Me lost :-|
TIA,
--shanko



Wed, 16 Nov 2005 10:37:20 GMT  
 IF statement in ruby 1.8.0 (2003-05-26) [i386-mswin32]

Quote:

> Just when I thought that I had perfectly understood the IF statement ...

This could be 'bug-lite' in 1.7+ (or i386)?

<code>
puts "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
la = []; set_trace_func proc {|t| la << t[2] if t[0] == 'line'}

a = 2 if true
p la
</code>

<out>
ruby 1.6.7 (2002-03-01) [i586-mswin32]
[4, 5]

ruby 1.7.2 (2002-07-02) [i386-mswin32]
[4, 4, 5]

ruby 1.7.3 (2002-11-17) [i386-mswin32]
[4, 4, 5]

ruby 1.8.0 (2003-05-15) [i386-mswin32]
[4, 4, 5]
</out>

daz



Wed, 16 Nov 2005 12:29:36 GMT  
 IF statement in ruby 1.8.0 (2003-05-26) [i386-mswin32]

Quote:


> > Just when I thought that I had perfectly understood the IF statement ...

> This could be 'bug-lite' in 1.7+ (or i386)?

Bug or a feature ? ;-)

Yes, I verified that I get different results on 1.6.8.
Thanks for pointing it out daz.



Wed, 16 Nov 2005 12:39:30 GMT  
 IF statement in ruby 1.8.0 (2003-05-26) [i386-mswin32]

S> Bug or a feature ? ;-)

 Well, you have 1 trace_func for NODE_NEWLINE and 1 for NODE_IF

 When you remove `0', you have removed NODE_NEWLINE

Guy Decoux



Wed, 16 Nov 2005 21:08:31 GMT  
 IF statement in ruby 1.8.0 (2003-05-26) [i386-mswin32]
Hi,

In message "Re: IF statement in ruby 1.8.0 (2003-05-26) [i386-mswin32]"

|> This could be 'bug-lite' in 1.7+ (or i386)?
|
|Bug or a feature ? ;-)

A feature.  This is added to accomplish better de{*filter*} tracing.
The call timing may be changed in the future.

                                                        matz.



Wed, 16 Nov 2005 21:47:23 GMT  
 IF statement in ruby 1.8.0 (2003-05-26) [i386-mswin32]

Quote:


> S> Bug or a feature ? ;-)

>  Well, you have 1 trace_func for NODE_NEWLINE and 1 for NODE_IF

Umm... what is the meaning / purpose of NODE_NEWLINE ?
Is this for all the control structures like while, case, until etc ?


Wed, 16 Nov 2005 22:35:13 GMT  
 IF statement in ruby 1.8.0 (2003-05-26) [i386-mswin32]

S> Umm... what is the meaning / purpose of NODE_NEWLINE ?

 In ruby-core matz has said

Y> Keep track of line number in the executing source file, for debugging
Y> and error reporting.

Guy Decoux



Wed, 16 Nov 2005 22:42:31 GMT  
 IF statement in ruby 1.8.0 (2003-05-26) [i386-mswin32]

Quote:

>  In ruby-core matz has said


> Y> Keep track of line number in the executing source file, for debugging
> Y> and error reporting.

Since I am not as conversant with Ruby source as you all are, I am still not
quite getting it. But looking at his reply to this question, I am sure Matz
is
planning to use it in future (for "call timing").


Thu, 17 Nov 2005 00:04:54 GMT  
 IF statement in ruby 1.8.0 (2003-05-26) [i386-mswin32]

Quote:

> |> This could be 'bug-lite' in 1.7+ (or i386)?
> |
> |Bug or a feature ? ;-)

> A feature.  This is added to accomplish better de{*filter*} tracing.
> The call timing may be changed in the future.

> matz.

< abbreviated ri 1.8 description>
------------------------------------------------- Kernel::set_trace_func
     set_trace_func( aProc ) -> aProc
     set_trace_func( nil ) -> nil
------------------------------------------------------------------------

     Events are: c-call, c-return, call , class, end,
     line (execute code on a new line), raise and return.
</>

puts "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
set_trace_func proc {| ev, fi, li, oi, bi, cl |
  printf("(%8s)   %s:%-2d (%10s) %s %8s\n",
    ev, fi[-11,11], li, oi.inspect, bi.to_s, cl) if ev == 'line'

Quote:
}

##- line 7
a =
 1
a = 2 if true
if true then a = 3 end
a -= 1 while a > 0

produces:-

ruby 1.8.0 (2003-05-15) [i386-mswin32]
(    line)   stf_line.rb:8  (       nil) #<Binding:0x257ab44>    false
(    line)   stf_line.rb:10 (       nil) #<Binding:0x257a97c>    false
(    line)   stf_line.rb:10 (       nil) #<Binding:0x257a1fc>    false
(    line)   stf_line.rb:11 (       nil) #<Binding:0x257a0c4>    false
(    line)   stf_line.rb:11 (       nil) #<Binding:0x2579f8c>    false
(    line)   stf_line.rb:11 (       nil) #<Binding:0x2579e54>    false
(    line)   stf_line.rb:12 (       nil) #<Binding:0x2579d1c>    false

Perhaps if calls other than the first were 'line+', the de{*filter*} could
accept 'line' and 'line+' while others could easily filter out the
extra detail.

We're not all 'node-dumpers' :-)

Very many thanks, Matz,

daz
--

"Not only that: He's handed out the fkn source code as well!"



Thu, 17 Nov 2005 13:24:43 GMT  
 IF statement in ruby 1.8.0 (2003-05-26) [i386-mswin32]

Quote:

> |> This could be 'bug-lite' in 1.7+ (or i386)?
> |
> |Bug or a feature ? ;-)

> A feature.  This is added to accomplish better de{*filter*} tracing.
> The call timing may be changed in the future.

What is "call timing" ? Time when a particular call was made ?


Fri, 18 Nov 2005 13:26:27 GMT  
 IF statement in ruby 1.8.0 (2003-05-26) [i386-mswin32]
Hi,
In message "Re: IF statement in ruby 1.8.0 (2003-05-26) [i386-mswin32]"

|> The call timing may be changed in the future.
|
|What is "call timing" ? Time when a particular call was made ?

Yes.  Duplicates may be removed again when I find workaround for
good de{*filter*} tracing.

                                                        matz.



Fri, 18 Nov 2005 17:18:04 GMT  
 IF statement in ruby 1.8.0 (2003-05-26) [i386-mswin32]

Quote:

> What is "call timing" ? Time when a particular call was made ?

I took this to mean that the frequency and/or sequence of
calls is "undefined" at present.  Don't write code in a
set_trace_func proc that depends on 'line' events being the
same in the future as they are now.

If this gives you a problem, you can save the line
number so that your proc is called only once per line.

Note that some single-line iterations are filtered out (lost)
even though multiple genuine new-line calls were received.

#----------------------------------------------------------------
prev_line = nil
set_trace_func proc {| event, fi, line, oi, bi, cl |
  case event
  when 'line'
    if (( true)) and prev_line == line  # <- change to ((!true))
      print '[+ ]'
    else
      printf("[%-2d]", line)
    end
  else
    print '.'  # other events
  end
  prev_line = line

Quote:
}

### line :15
def roo
  3.times do
    0
  end
end
a =
 1
a = 2 if true
if true then a = 3 end
a = 4; a -= 1 while a > 0
2.times do
  z = 5
end
2.times do
  z = 6
  +7
end
roo
#----------------------------------------------------------------

Change (( true)) to (( !true)) on line 5 to remove the filter

[+ ] shows a repeat of the prior line [nn]
     all other events show as dots
Results:
Two long lines from two runs split and grouped       (IfYouKnowWhatIMean)

[16]..[21][23][+ ][24][+ ][+ ][25][+ ]...............           (( true))
[16]..[21][23][23][24][24][24][25][25]...............           ((!true))

...[26].[27][+ ].[29].[30][31][30][31].[33].[17].[18][+ ][+ ].. (( true))
...[26].[27][27].[29].[30][31][30][31].[33].[17].[18][18][18].. ((!true))

I'm sure others will step in and help if you're not happy
or if I've triggered a GC.start -

(I've seen Matz has replied to you.  Posting anyway.)

daz
--
Slap me; I feel little pain.  ;-)



Fri, 18 Nov 2005 21:23:36 GMT  
 IF statement in ruby 1.8.0 (2003-05-26) [i386-mswin32]

Quote:

> |What is "call timing" ? Time when a particular call was made ?

> Yes.  Duplicates may be removed again when I find workaround for
> good de{*filter*} tracing.

Great ! I am using this precisely for de{*filter*} tracing ... so looking
forward to any improvements in the process.

Thanks Matz.



Fri, 18 Nov 2005 21:32:30 GMT  
 
 [ 16 post ]  Go to page: [1] [2]

 Relevant Pages 

1. ruby 1.7.3 [i386-mswin32] and mysql.so

2. Problem with FXRuby 1.0.13/ruby 1.7.2 (i386-mswin32)

3. Mysql & Ruby (mswin32)

4. Where to get Ruby(mswin32)/Gtk?

5. , ruby 1.6.8 (2002-12-24) [i586-mswin32]

6. Ruby extension mingw32 libraries on mswin32?

7. Windows ports: performance of cygwin vs mswin32 ruby

8. GTK+ for mswin32 ruby binaries?

9. How does one _really_ install Ruby-mswin32?

10. EOF on ruby-mswin32 ...

11. Questions building i586-mswin32 version of Ruby

12. Building mswin32 ruby

 

 
Powered by phpBB® Forum Software