2011-10-17 50 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,存储,[天气,冷])。

它显示错误:

([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' 

我认为这是对Linux的主机名,

,但我用这个Linux shell中:主机名-a

它不能显示“huihua.sohu-INC .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]作为两个原子之间的差操作。我建议你按照erlang提供的报价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 @.