我在七周内学习七种语言"。
在Io charpter上,我运行以下示例失败并出现以下异常。
#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
{
"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。
答案 0 :(得分:1)
逐行比较代码
s := File with("phonebook.txt" openForReading contents)
应更正为:
s := File with("phonebook.txt") openForReading contents
最后按预期工作:
$> io phonebook.io
名单(玛丽沃尔什,鲍勃史密斯)
列表(5678,12345)