2011年3月10日木曜日

Erlang binary_to_existing_atom

binary_to_existing_atom(Binary, Encoding) -> atom()
Types:
Binary = binary()
Encoding = latin1 | utf8 | unicode

Works like binary_to_atom/2, but the atom must already exist.
(binary_to_atom/2と同様の動作をする、しかし、アトムじゃないとダメ)

Failure: badarg if the atom does not already exist.
(引数のバイナリはアトム以外があるとNG)


36> binary_to_existing_atom(<<"Erlang">>,latin1).
'Erlang'
37> binary_to_existing_atom(<<100>>,latin1).    
d
38> binary_to_existing_atom(<<67>>,latin1).
** exception error: bad argument
     in function  binary_to_existing_atom/2
        called as binary_to_existing_atom(<<"C">>,latin1)
39> binary_to_existing_atom(<<67>>,latin1).
** exception error: bad argument
     in function  binary_to_existing_atom/2
        called as binary_to_existing_atom(<<"C">>,latin1)
40> binary_to_existing_atom(<<69>>,latin1).
** exception error: bad argument
     in function  binary_to_existing_atom/2
        called as binary_to_existing_atom(<<"E">>,latin1)
41> binary_to_existing_atom(<<109>>,latin1).
m
42> binary_to_existing_atom(<<109>>,utf8).
m
43> binary_to_existing_atom(<<69>>,utf8).
** exception error: bad argument
     in function  binary_to_existing_atom/2
        called as binary_to_existing_atom(<<"E">>,utf8)
44> binary_to_existing_atom(<<"E">>,utf8).
** exception error: bad argument
     in function  binary_to_existing_atom/2
        called as binary_to_existing_atom(<<"E">>,utf8)
45> binary_to_existing_atom(<<"e">>,utf8).
e
46> binary_to_existing_atom(<<"Er">>,utf8).
** exception error: bad argument
     in function  binary_to_existing_atom/2
        called as binary_to_existing_atom(<<"Er">>,utf8)
47>

なぜ”Erlang”がOKで”Er”はNGなのか謎。

0 件のコメント:

コメントを投稿