Skip to content

Unexpected behavior of Object doMessage #438

Open
@ales-tsurko

Description

@ales-tsurko

I'm trying to implement a basic JSON parser in Io to get rid of parson dependency. It looks like a very easy task, but I faced a problem, which just blows my mind... Here's the code:

Json := Object clone do (
    squareBrackets := Object getSlot("list")

    curlyBrackets := method(
        map := Map clone
        call message arguments foreach(arg,
            "arg is '#{arg}'" interpolate println
            pair := Sequence doMessage(arg)
            "pair is '#{pair}'" interpolate println
            map atPut(pair at(0), pair at(1)))
        map)

    Sequence : := method(
        "Sequence ':' message is '#{call message}'" interpolate println
        list(self, Json doMessage(call message last)))
)

Json clone := Json

When I use this "library" in a script:

Importer addSearchPath("io")

m := Json { "h": 1 }

I get:

arg is '"h" : 1'
Sequence ':' message is ': 1'
pair is '1'

  Exception: argument 0 to method 'atPut' must be a Sequence, not a 'Number'
  ---------
  atPut                               Json.io 10
  Json curlyBrackets                   tes.io 3
  CLI doFile                           Z_CLI.io 140
  CLI run                              IoState_runCLI() 1

As you can see the Sequence's : method is called when it should and the message which this method gets is correct, but for some reason the result is always the last message in the chain. It's ignoring everything I return from Sequence : . I tried a hard-coded value as well but no luck. What am I doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions