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 :expressionless:
TIA,
–shanko

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

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

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]

daz

···

“Shashank Date” sdate@everestkc.net wrote:

Just when I thought that I had perfectly understood the IF statement …

“daz” dooby@d10.karoo.co.uk wrote in message

···

“Shashank Date” sdate@everestkc.net wrote:

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 ? :wink:

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

Bug or a feature ? :wink:

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

Hi,

···

In message “Re: IF statement in ruby 1.8.0 (2003-05-26) [i386-mswin32]” on 03/05/31, “Shashank Date” sdate@everestkc.net writes:

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

Bug or a feature ? :wink:

A feature. This is added to accomplish better debugger tracing.
The call timing may be changed in the future.

						matz.

“ts” decoux@moulon.inra.fr wrote in message

Bug or a feature ? :wink:

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 ?

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

···

“Yukihiro Matsumoto” matz@ruby-lang.org wrote:

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

Bug or a feature ? :wink:

A feature. This is added to accomplish better debugger tracing.
The call timing may be changed in the future.

matz.


 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’
}
##- 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 debugger could
accept ‘line’ and ‘line+’ while others could easily filter out the
extra detail.

We’re not all ‘node-dumpers’ :slight_smile:

Very many thanks, Matz,

daz

“Not only that: He’s handed out the fkn source code as well!”

“Yukihiro Matsumoto” matz@ruby-lang.org wrote in message

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

Bug or a feature ? :wink:

A feature. This is added to accomplish better debugger tracing.
The call timing may be changed in the future.

What is “call timing” ? Time when a particular call was made ?

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

In ruby-core matz has said

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

Guy Decoux

Hi,

···

In message “Re: IF statement in ruby 1.8.0 (2003-05-26) [i386-mswin32]” on 03/06/02, “Shashank Date” sdate@everestkc.net writes:

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 debugger tracing.

						matz.

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.

···

“Shashank Date” sdate@everestkc.net wrote:

What is “call timing” ? Time when a particular call was made ?

#----------------------------------------------------------------
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
}

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. :wink:

“ts” decoux@moulon.inra.fr wrote in message

In ruby-core matz has said

Keep track of line number in the executing source file, for debugging
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”).

“Yukihiro Matsumoto” matz@ruby-lang.org wrote in message

What is “call timing” ? Time when a particular call was made ?

Yes. Duplicates may be removed again when I find workaround for
good debugger tracing.

Great ! I am using this precisely for debugger tracing … so looking
forward to any improvements in the process.

Thanks Matz.

“daz” dooby@d10.karoo.co.uk wrote in message
[snip]

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

This is excellent … of course, suggestions to improve are always welcome.
Thanks a lot daz.
– shanko