Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

iteration.mon : wrong hash key/value #90

Closed

Description

@wade-fs

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

Activity

  1. skx commented on Nov 11, 2023

    @skx
    Owner

    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.)

  2. added a commit that references this issue on Nov 11, 2023
    52cb20b
  3. skx commented on Nov 11, 2023

    @skx
    Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions