0

我正在学习“七周内的七种语言”。

在 Io 章上,我运行以下示例失败并出现以下异常。

#phonebook.io
OperatorTable addAssignOperator(":", "atPutNumber")
curlyBrackets := method(
  r := Map clone
  call message arguments foreach(arg,
       r doMessage(arg)
       )
  r
)

Map atPutNumber := method(
  self atPut(
       call evalArgAt(0) asMutable removePrefix("\"") removeSuffix("\""),
       call evalArgAt(1))
)

s := File with("phonebook.txt" openForReading contents)

phoneNumbers := doString(s)
phoneNumbers keys println
phoneNumbers values println

电话簿.txt

{
        "Bob  Smith" : "12345",
        "Mary Walsh" : "5678"
}

异常消息:

例外:序列不响应 'openForReading' ---------
序列 openForReading phonebook.io 16 带有
phonebook.io 的文件 16 CLI doFile Z_CLI.io 140
CLI 运行 IoState_runCLI() 1

phonebook.io 和 phonebook.txt 在同一个文件夹中。

4

1 回答 1

1

逐行比较代码,下一行

s := File with("phonebook.txt" openForReading contents)

应更正为:

s := File with("phonebook.txt") openForReading contents

最后按预期工作:

$> io phonebook.io
list(Mary Walsh, Bob Smith)
list(5678, 12345)

于 2014-08-01T07:50:12.150 回答