Io语言的addAssignOperator在使用文件执行的时候会出现添加不进去的bug,
同时addOperator添加进来的运算符全都是单目运算符。(也许也是添加不进去的表现,待研究。)
在七天七语言的Io章Day3练习3中,为了绕过这两个bug,我的代码如下:
Builder := Object clone
Builder indent := 0
Builder forward := method(
write(" " repeated(self indent * 2))
write("<", call message name)
arguments := call message arguments
if (arguments first name == "curlyBrackets",
doMessage(arguments removeFirst)
)
writeln(">")
self indent = self indent + 1
arguments foreach(argument,
content := self doMessage(argument)
if(content type == "Sequence",
write(" " repeated(self indent * 2))
writeln(doMessage(argument))
)
)
self indent = self indent - 1
write(" " repeated(self indent * 2))
writeln("</", call message name, ">")
)
curlyBrackets := method(
call message arguments foreach(argument,
value := doMessage(argument)
write("=\"", value, "\"")
)
)
Sequence : := method(n,
write(" ", self)
)
(Builder ul(
{"size" : "3"},
li("a"),
li("b"),
"c"
))
PS. 这篇Stackoverflow解答中说只有Mac有这个Bug,经过我测试Windows中也有这个Bug,Linux未测。