2014-12-12 7 views
1

나는 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 

호 (다시 말하지만,이 코드는. 바로 책입니다) 그리고 수단 " '부울'에 응답하지 않습니다"모르겠어요.

+0

이 'bool'은 무엇입니까? – Bergi

답변

6

쉼표를 잊어 버리고 첫 번째 메시지가 bool 인 매개 변수없는 메소드를 정의했습니다. true (그 위에 호출 됨)은 아무 것도 모릅니다. 원하는 작업은

+1

오타를 지적하고 저에게 몇 가지 것을 가르쳐주는 훌륭한 답변을 보내 주셔서 감사합니다! –