Need help to detect error

  • Thread starter Víctor Adrián de la Cruz Serrano
  • Start date
V

Víctor Adrián de la Cruz Serrano

I don't know what am I doing wrong, can anyone help me?
These two programs look very similar, but they yield different results.
Can anyone confirm this "error"?


=================================================================
# FAILING EXAMPLE
=================================================================
class Battlefield
attr_accessor :teams
def initialize
@teams = []
end
def add_team(team)
@teams << team
team.bparent = self
end
end

class Team
attr_accessor :members, :bparent
def initialize
@members = []
@bparent = nil
end
def add_member(child)
@members << child
child.team = self
end
end

class Warrior
attr_accessor :team
def initialize
@team = nil
end
end

w = Warrior.new
t = Team.new
t.add_member(w)
b = Battlefield.new
b.add_team(t)
b.inspect
#Convert to YAML and back
y = YAML.load(b.to_yaml)
#Now have a look at the "members" array inside a team... it's gone
y.inspect
y.teams.first.members.inspect


=================================================================
# GOOD EXAMPLE
=================================================================
require 'yaml'

class Battlefield
attr_accessor :teams
def initialize
@teams = []
end
def add_team(team)
@teams << team
team.parent = self
end
end

class Team
attr_accessor :members, :parent
def initialize
@members = []
@parent = nil
end
def add_member(child)
@members << child
child.team = self
end
end

class Warrior
attr_accessor :team
def initialize
@team = nil
end
end

w = Warrior.new
t = Team.new
t.add_member(w)
b = Battlefield.new
b.add_team(t)
b.inspect
#Convert to YAML and back
y = YAML.load(b.to_yaml)
#Now have a look at the "members" array inside a team, it's still there
y.inspect
y.teams.first.members.inspect
 
V

Víctor Adrián de la Cruz Serrano

Or anyone knows where can I contact some YAML guys to help me with this
obscure problem?

El mi=C3=A9, 11-11-2009 a las 16:58 +0900, V=C3=ADctor Adri=C3=A1n de la Cr=
uz Serrano
escribi=C3=B3:
 
J

Judson Lester

That's bizarre. All that I can see that's different is because the failing
version uses the attribute "bparent" and the other uses "parent", the
backreferences occur in different places in the resulting YAML. I believe
that Syck was taking over when _why left - you ought to file a bug.

(Unless there's an obscure YAML rule that backreferences have to occur afte=
r
literal values...)

Judson

2009/11/11 V=C3=ADctor Adri=C3=A1n said:
Or anyone knows where can I contact some YAML guys to help me with this
obscure problem?

El mi=C3=A9, 11-11-2009 a las 16:58 +0900, V=C3=ADctor Adri=C3=A1n de la = Cruz Serrano
escribi=C3=B3:
I don't know what am I doing wrong, can anyone help me?
These two programs look very similar, but they yield different results.
Can anyone confirm this "error"?


=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
# FAILING EXAMPLE
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
class Battlefield
attr_accessor :teams
def initialize
@teams =3D []
end
def add_team(team)
@teams << team
team.bparent =3D self
end
end

class Team
attr_accessor :members, :bparent
def initialize
@members =3D []
@bparent =3D nil
end
def add_member(child)
@members << child
child.team =3D self
end
end

class Warrior
attr_accessor :team
def initialize
@team =3D nil
end
end

w =3D Warrior.new
t =3D Team.new
t.add_member(w)
b =3D Battlefield.new
b.add_team(t)
b.inspect
#Convert to YAML and back
y =3D YAML.load(b.to_yaml)
#Now have a look at the "members" array inside a team... it's gone
y.inspect
y.teams.first.members.inspect


=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
# GOOD EXAMPLE
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
require 'yaml'

class Battlefield
attr_accessor :teams
def initialize
@teams =3D []
end
def add_team(team)
@teams << team
team.parent =3D self
end
end

class Team
attr_accessor :members, :parent
def initialize
@members =3D []
@parent =3D nil
end
def add_member(child)
@members << child
child.team =3D self
end
end

class Warrior
attr_accessor :team
def initialize
@team =3D nil
end
end

w =3D Warrior.new
t =3D Team.new
t.add_member(w)
b =3D Battlefield.new
b.add_team(t)
b.inspect
#Convert to YAML and back
y =3D YAML.load(b.to_yaml)
#Now have a look at the "members" array inside a team, it's still there
y.inspect
y.teams.first.members.inspect
 
V

Víctor Adrián de la Cruz Serrano

Yeah, but I don't know where exactly should I report it. What is the
link to their bug tracker?

Exactly, the difference is only one char.
And I have found that it works with words like: parent, parenta,
parenton, parent.
But it fails with words like: battle, battlefield, bparent.

Strange, isn't it?

El jue, 12-11-2009 a las 09:41 +0900, Judson Lester escribi=C3=B3:
That's bizarre. All that I can see that's different is because the faili= ng
version uses the attribute "bparent" and the other uses "parent", the
backreferences occur in different places in the resulting YAML. I believ= e
that Syck was taking over when _why left - you ought to file a bug.
=20
(Unless there's an obscure YAML rule that backreferences have to occur af= ter
literal values...)
=20
Judson
=20
2009/11/11 V=C3=ADctor Adri=C3=A1n said:
Or anyone knows where can I contact some YAML guys to help me with this
obscure problem?

El mi=C3=A9, 11-11-2009 a las 16:58 +0900, V=C3=ADctor Adri=C3=A1n de l= a Cruz Serrano
escribi=C3=B3:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
class Battlefield
attr_accessor :teams
def initialize
@teams =3D []
end
def add_team(team)
@teams << team
team.bparent =3D self
end
end

class Team
attr_accessor :members, :bparent
def initialize
@members =3D []
@bparent =3D nil
end
def add_member(child)
@members << child
child.team =3D self
end
end

class Warrior
attr_accessor :team
def initialize
@team =3D nil
end
end

w =3D Warrior.new
t =3D Team.new
t.add_member(w)
b =3D Battlefield.new
b.add_team(t)
b.inspect
#Convert to YAML and back
y =3D YAML.load(b.to_yaml)
#Now have a look at the "members" array inside a team... it's gone
y.inspect
y.teams.first.members.inspect


=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
require 'yaml'

class Battlefield
attr_accessor :teams
def initialize
@teams =3D []
end
def add_team(team)
@teams << team
team.parent =3D self
end
end

class Team
attr_accessor :members, :parent
def initialize
@members =3D []
@parent =3D nil
end
def add_member(child)
@members << child
child.team =3D self
end
end

class Warrior
attr_accessor :team
def initialize
@team =3D nil
end
end

w =3D Warrior.new
t =3D Team.new
t.add_member(w)
b =3D Battlefield.new
b.add_team(t)
b.inspect
#Convert to YAML and back
y =3D YAML.load(b.to_yaml)
#Now have a look at the "members" array inside a team, it's still the= re
y.inspect
y.teams.first.members.inspect
 
J

Judson Lester

The single character difference tends to corroborate the cause of the bug:
the reference that's generated by #to_yaml fails if it comes earlier in the
map - first, not last, not sure the details.

As to where to post bugs, Syck has been accepted into the standard library
(one of many incredible contributions by _why) so I'd imagine that the bugs
would be posted to http://redmine.ruby-lang.org/

Judson

2009/11/12 V=C3=ADctor Adri=C3=A1n said:
Yeah, but I don't know where exactly should I report it. What is the
link to their bug tracker?

Exactly, the difference is only one char.
And I have found that it works with words like: parent, parenta,
parenton, parent.
But it fails with words like: battle, battlefield, bparent.

Strange, isn't it?

El jue, 12-11-2009 a las 09:41 +0900, Judson Lester escribi=C3=B3:
That's bizarre. All that I can see that's different is because the failing
version uses the attribute "bparent" and the other uses "parent", the
backreferences occur in different places in the resulting YAML. I believe
that Syck was taking over when _why left - you ought to file a bug.

(Unless there's an obscure YAML rule that backreferences have to occur after
literal values...)

Judson
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
class Battlefield
attr_accessor :teams
def initialize
@teams =3D []
end
def add_team(team)
@teams << team
team.bparent =3D self
end
end

class Team
attr_accessor :members, :bparent
def initialize
@members =3D []
@bparent =3D nil
end
def add_member(child)
@members << child
child.team =3D self
end
end

class Warrior
attr_accessor :team
def initialize
@team =3D nil
end
end

w =3D Warrior.new
t =3D Team.new
t.add_member(w)
b =3D Battlefield.new
b.add_team(t)
b.inspect
#Convert to YAML and back
y =3D YAML.load(b.to_yaml)
#Now have a look at the "members" array inside a team... it's gone
y.inspect
y.teams.first.members.inspect


=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
require 'yaml'

class Battlefield
attr_accessor :teams
def initialize
@teams =3D []
end
def add_team(team)
@teams << team
team.parent =3D self
end
end

class Team
attr_accessor :members, :parent
def initialize
@members =3D []
@parent =3D nil
end
def add_member(child)
@members << child
child.team =3D self
end
end

class Warrior
attr_accessor :team
def initialize
@team =3D nil
end
end

w =3D Warrior.new
t =3D Team.new
t.add_member(w)
b =3D Battlefield.new
b.add_team(t)
b.inspect
#Convert to YAML and back
y =3D YAML.load(b.to_yaml)
#Now have a look at the "members" array inside a team, it's still there
y.inspect
y.teams.first.members.inspect
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top