簡體   English   中英

為什么Erlang字符串不能用作ets表名?

[英]why Erlang string can't used as ets table name?

我是動態創建ets表的,所以最好避免使用原子作為名稱。
簡單使用字符串作為名稱,例如:
:ets.new("aaa", [:named_table])

但是無法編譯:

** (ArgumentError) argument error
    (stdlib) :ets.new("aaa", [])

如果要動態創建ETS表,一種方法是將它們創建為未命名的表,並使用:ets.new返回的表ID來訪問它們:

iex(1)> table1 = :ets.new(:foo, [])
8212
iex(2)> table2 = :ets.new(:foo, [])
12309
iex(3)> :ets.insert(table1, {:a, 1})
true
iex(4)> :ets.insert(table2, {:a, 2})
true
iex(5)> :ets.lookup(table1, :a)
[a: 1]
iex(6)> :ets.lookup(table2, :a)
[a: 2]

(在Erlang / OTP 20.0中,表id是一個引用而不是整數,但是它的工作方式相同;請參見此問題 。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM