Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iteration.mon : wrong hash key/value #90

Closed
wade-fs opened this issue Nov 10, 2023 · 2 comments · Fixed by #91
Closed

iteration.mon : wrong hash key/value #90

wade-fs opened this issue Nov 10, 2023 · 2 comments · Fixed by #91

Comments

@wade-fs
Copy link

wade-fs commented Nov 10, 2023

When I execute iteration.mon, I got wrong :

Hash: key
Foo
Steve
Hash: key/value
Bar => Foo
Bar => Foo

When I rewrite script to:
_h = { "Foo": "Bar", "Steve": "Kemp", "Name": "Wade" }
puts( "Hash: key\n")
foreach key in h {
puts( "\t", key, "\n");
}

hh = { "Foo": "Bar", "Steve": "Kemp", "Name": "Wade" }
puts( "Hash: key/value\n")
foreach key,val in hh {
puts( "\t", key, "\t=>\t", val, "\n");
}_

I got:
Hash: key
Steve
Foo
Steve
Hash: key/value
Bar => Foo
Kemp => Steve
Wade => Name

@skx
Copy link
Owner

skx commented Nov 11, 2023

OK there is something going wrong here. So your first example is this:

h = { "Foo": "Bar", "Steve": "Kemp", "Name": "Wade" }
puts( "Hash: key\n")

foreach key in h {
        puts( "\t", key, "\n");
}

That produces:

Hash: key
	Steve
	Name
	Name

So the issue there seems to be that the first entry was skipped, and the second was duplicated. I'll take a look now.

(The second example you post I think is the same. The first item is skipped, and the second is repeated.)

skx added a commit that referenced this issue Nov 11, 2023
This commit adds a test-case which checks that the iteration
over hash keys returns the correct results.  It seems that the
value varies over runs - so repeating the test ten times is
likely sufficient to trigger the issue.

Once this bug is fixed this will close #90.
@skx
Copy link
Owner

skx commented Nov 11, 2023

Seems that re-running this code again and again gives different results. Added a test-case in #91, and will resolve it there.

@skx skx closed this as completed in #91 Nov 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants