Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > `concat': can't modify frozen string in benchmark.rb

Reply
Thread Tools

`concat': can't modify frozen string in benchmark.rb

 
 
Peña, Botp
Guest
Posts: n/a
 
      05-31-2007
Hi All,

C:\family\ruby>cat test.rb
def f(command_here)
`#{command_here}`
end
a =3D { "Local copy"=3D>"copy test.txt test.txt2" }
require 'benchmark'
Benchmark.bmbm do |x|
a.each do |k,v|
x.report(k) { f v }
end
end

C:\family\ruby>ruby test.rb
c:/ruby/lib/ruby/1.8/benchmark.rb:334:in `concat': can't modify frozen =
string (T
ypeError)
from c:/ruby/lib/ruby/1.8/benchmark.rb:334:in `report'
from test.rb:12
from test.rb:11:in `each'
from test.rb:11
from c:/ruby/lib/ruby/1.8/benchmark.rb:250:in `bmbm'
from test.rb:10
C:\family\ruby>

if i comment out line 334 in benchmark.rb like so,

#label.concat ' '

It works.
It also works for the ff cases
x.report(k) { f v }
x.report() { f v }
x.report("") { f v }
x.report("test") { f v }

What is the relevance of line 334 in benchmark.rb?
If the line is important, how can I fix my program so I can pass a var =
in x.report?

thank you and kind regards -botp

 
Reply With Quote
 
 
 
 
Joel VanderWerf
Guest
Posts: n/a
 
      05-31-2007
Peña wrote:
> Hi All,
>
> C:\family\ruby>cat test.rb
> def f(command_here)
> `#{command_here}`
> end
> a = { "Local copy"=>"copy test.txt test.txt2" }
> require 'benchmark'
> Benchmark.bmbm do |x|
> a.each do |k,v|
> x.report(k) { f v }
> end
> end
>
> C:\family\ruby>ruby test.rb
> c:/ruby/lib/ruby/1.8/benchmark.rb:334:in `concat': can't modify frozen string (T
> ypeError)
> from c:/ruby/lib/ruby/1.8/benchmark.rb:334:in `report'
> from test.rb:12
> from test.rb:11:in `each'
> from test.rb:11
> from c:/ruby/lib/ruby/1.8/benchmark.rb:250:in `bmbm'
> from test.rb:10
> C:\family\ruby>
>
> if i comment out line 334 in benchmark.rb like so,
>
> #label.concat ' '
>
> It works.
> It also works for the ff cases
> x.report(k) { f v }
> x.report() { f v }
> x.report("") { f v }
> x.report("test") { f v }
>
> What is the relevance of line 334 in benchmark.rb?
> If the line is important, how can I fix my program so I can pass a var in x.report?
>
> thank you and kind regards -botp
>


A quick workaround would be to use k.dup:

x.report(k.dup) { f v }

Apparently, benchmark is being bad and munging its inputs (and falling
down when one of them happens to be frozen because it is also a hash key).

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

 
Reply With Quote
 
 
 
 
Peña, Botp
Guest
Posts: n/a
 
      05-31-2007
From: Joel VanderWerf [(E-Mail Removed)] :
# A quick workaround would be to use k.dup:
#=20
# x.report(k.dup) { f v }

brilliant insight. I never even tested that, thinking k.dup would just =
be another var/object. And besides, it does not even look *right

# Apparently, benchmark is being bad and munging its inputs=20
# (and falling=20
# down when one of them happens to be frozen because it is also=20
# a hash key).

it is really weird.
thank you and kind regards -botp

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling xpython: No rule to make target `runathana.py', needed by `frozen/frozen.c'. est Python 1 10-11-2010 03:35 AM
Rexml pretty printing "can't modify frozen string" Une Bévue Ruby 3 04-25-2010 10:23 AM
safe to modify frozen object from C? Joel VanderWerf Ruby 2 04-26-2004 05:11 AM
Frozen string problem, but I haven't frozen anything? LC Geldenhuys Ruby 5 02-18-2004 08:13 AM
modify a frozen object Elias Athanasopoulos Ruby 0 11-13-2003 05:58 PM



Advertisments