【问题标题】:Io Language: Exception: Sequence does not respond to 'openForReading'Io 语言:异常:序列不响应“openForReading”
【发布时间】:2014-08-01 01:55:03
【问题描述】:

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

在 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 在同一个文件夹中。

【问题讨论】:

    标签: iolanguage


    【解决方案1】:

    逐行比较代码,下一行

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

    应正确为:

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

    终于按预期工作了:

    $> io phonebook.io
    名单(玛丽·沃尔什,鲍勃·史密斯)
    列表(5678, 12345)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多