얼랑

2011-10-17 2 views
2

내 호스트 이름을 변경하는 방법이 내 kvs.erl입니다 :얼랑

-module(kvs). 
-export([start/0, store/2, lookup/1]). 

start() -> register(kvs, spawn(fun() -> loop() end)). 

store(Key, Value) -> rpc({store, Key, Value}). 

lookup(Key) -> rpc({lookup, Key}). 

rpc(Q) -> 
    kvs ! {self(), Q}, 
    receive 
    {kvs, Reply} -> 
     Reply 
    end. 

loop() -> 
    receive 
    {From, {store, Key, Value}} -> 
     put(Key, {ok, Value}), 
     From ! {kvs, true}, 
     loop(); 
    {From, {lookup, Key}} -> 
     From ! {kvs, get(Key)}, 
     loop() 
    end. 

내가 사용 얼랑 시작 : ERL -name의 자오 -setcookie abc 방송

다음 : RPC : fifar 전화를 (@ huihua.sohu-inc.com, kvs, store, [날씨, 추위]).

가 보여 오류 : 호스트 이름

그것은 "huihua.sohu-INC를 보여 질수 -a :

([email protected])1> rpc:call([email protected],kvs,store,[weather,cold]).   
** exception error: bad argument in an arithmetic expression 
    in operator -/2 
     called as '[email protected]' - 'inc.com' 

내가 생각이 리눅스 호스트에 관한,

하지만 난이 리눅스 쉘을 사용 .COM "

그래서 내가 무엇을 할 수 있는지,

감사

답변

5

오류 설명을 보면 바이너리 연산자 "-"에 오류가 있습니다. 당신은 단지

([email protected])1> rpc:call([email protected],kvs,store,[weather,cold]). 

([email protected])1> rpc:call('[email protected]',kvs,store,[weather,cold]). 

을 변경해야 할 것입니다 그리고 당신은 당신의 코드가 실행 얻을 것이다. 얼랑 콘솔은 두 개의 다른 원자로서 [email protected] 및 inc.com 보는 두 원자 사이차분 동작으로서 [email protected]보고된다. 나는이 조언을 따라달라고 조언한다. reference manual :

An atom is a literal, a constant with name. An atom should be enclosed in single quotes (') if it does not begin with a lower-case letter or if it contains other characters than alphanumeric characters, underscore (_), or @.