私は、第 3 章の Day to of Seven Languages in Seven Weeks (「The Sausage King」) に取り組んでいます。本からコードをそのままコピーしましたが、機能しません。
Io 20110905
OperatorTable に新しい演算子を追加します。
Io> OperatorTable addOperator("xor", 11)
==> OperatorTable_0x336040:
Operators
0 ? @ @@
1 **
2 % * /
3 + -
4 << >>
5 < <= > >=
6 != ==
7 &
8 ^
9 |
10 && and
11 or xor ||
12 ..
13 %= &= *= += -= /= <<= >>= ^= |=
14 return
Assign Operators
::= newSlot
:= setSlot
= updateSlot
To add a new operator: OperatorTable addOperator("+", 4) and implement the + message.
To add a new assign operator: OperatorTable addAssignOperator("=", "updateSlot") and implement the updateSlot message.
出力は、それがスロット 11 に追加されたことを確認します。ここで、true にまだ xor メソッドが定義されていないことを確認しましょう。
Io> true slotNames
==> list(not, asString, asSimpleString, type, else, ifFalse, ifTrue, then, or, elseif, clone, justSerialized)
そうではありません。それでは作成してみましょう。
Io> true xor := method(bool if(bool, false, true))
==> method(
bool if(bool, false, true)
)
また、false の場合も 1 つです。
Io> false xor := method(bool if(bool, true, false))
==> method(
bool if(bool, true, false)
)
xor 演算子が追加されたことを確認します。
Io> true slotNames
==> list(not, asString, asSimpleString, type, else, xor, ifFalse, ifTrue, then, or, elseif, clone, justSerialized)
偉大な。使えますか?(繰り返しますが、このコードは本から直接引用したものです。)
Io> true xor true
Exception: true does not respond to 'bool'
---------
true bool Command Line 1
true xor Command Line 1
いいえ。「bool に応答しない」の意味がわかりません。