나는 3 장, 하루 Seven Languages in Seven Weeks ("The Sausage King")까지 연구 중이다. 책에서 코드를 바로 복사했지만 작동하지 않습니다.Io에서 xor 연산자를 정의하는 방법
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.
출력
는 이제 이미 XOR 방법은 정의가없는 사실 확인하자 슬롯 11에 추가되었는지 확인합니다.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)
)
그리고 허위도 마찬가지입니다.
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'은 무엇입니까? – Bergi