MidnightLightning
MidnightLightning

Reputation: 6928

io Assignment Operator not evaluating?

OperatorTable addAssignOperator(":", "myAssignMethod")
"foo" : "bar"

That gives an error that a Sequence does not respond to ":" (":" is still being treated as a message, not an operator).

I think it should get evaluated to myAssignMethod("foo", "bar") (since "foo" = "bar" becomes updateSlot("foo", "bar")), but it's not. However:

OperatorTable addAssignOperator(":", "myAssignMethod")
doString("\"foo\" : \"bar\"")

that does work properly, and myAssignMethod gets called. So how do I get whatever processing happens on the code during doString() to work in the main code of the file?

Upvotes: 3

Views: 199

Answers (2)

MidnightLightning
MidnightLightning

Reputation: 6928

Turns out this appears to be a bug in the Mac environment that was fixed recently; I was working off the MacPorts build of Io, and the '20090105' version of the environment has this bug. Running the same code on the Windows/Linux binaries resulted in the expected behavior.

Upvotes: 0

jer
jer

Reputation: 20236

: is a valid identifier, and has special meaning. It's used to indicate number of arguments in the objective-c binding. It's highly recommended you choose another operator.

Also note, that all operator table modifications must be done prior to your file you're using them in being loaded and parsed, since operator shuffling occurs at compile time (when the file is loaded) and not at evaluation time. The REPL hides this problem as it has a new compile with each time you hit enter.

Additionally, if you want to see what something will be compiled to (useful for operators) wrap it inside a message() call. i.e., message(1 + 2) will yield 1 +(2) in the REPL.

Upvotes: 7

Related Questions