Erlang/ets:在获得“a”后重置ets表;错误的论点;?

Erlang/ets:在获得“a”后重置ets表;错误的论点;?,erlang,ets,Erlang,Ets,我一直在学习如何使用ets,但有一件事困扰着我,那就是,ets:match偶尔会抛出一个坏参数…并且,从它们开始,所有后续调用(即使是以前有效的调用)也会抛出一个坏参数: > ets:match(Tid, { [$r | '$1'] }, 1). % this match works... % Then, at some point, this comes up: ** exception error: bad argument in function ets:match/3

我一直在学习如何使用ets,但有一件事困扰着我,那就是,
ets:match
偶尔会抛出一个
坏参数
…并且,从它们开始,所有后续调用(即使是以前有效的调用)也会抛出一个
坏参数

> ets:match(Tid, { [$r | '$1'] }, 1). % this match works... % Then, at some point, this comes up: ** exception error: bad argument in function ets:match/3 called as ets:match(24589,{[114|'$1']},1) % And from then on, matches stop working: > ets:match(Tid, { [$r | '$1'] }, 1). ** exception error: bad argument in function ets:match/3 called as ets:match(24589,{[114|'$1']},1) >ets:match(Tid,{[$r}'$1']},1)。 %这场比赛有效。。。 %然后,在某一点上,出现了: **异常错误:参数错误 功能中的ets:匹配/3 称为ets:match(24589,{[114 |'$1']},1) %从那时起,火柴停止工作: >ets:match(Tid,{[$r}'$1']},1)。 **异常错误:参数错误 功能中的ets:匹配/3 称为ets:match(24589,{[114 |'$1']},1) 有没有办法“重置”ets系统,以便我可以再次查询它(即从shell查询)


*:我无法重现这个问题……但在我尝试做“其他事情”时,它经常发生。

虽然我不是100%确定,但似乎能回答您的问题。看起来您正在壳中观察这种行为。如果是这样,两个事实以令人困惑的方式相互作用:

  • ets表在其所属进程结束后立即被删除
  • erlang shell在收到异常并以静默方式重新启动时死亡

  • 因此,当您获得第一个异常时,当前shell进程将终止,导致ets表被删除,然后为您启动一个新的shell进程。现在,当您尝试另一个
    ets:match
    时,它失败了,因为该表不再存在。

    Dale已经告诉您发生了什么。您可以通过不时在shell中调用self()来确认这一点

    作为一种快速解决方法,您可以生成另一个进程来为您创建公共表。那么那张桌子就不会和你的壳一起死了

    1> self().
    <0.32.0>    % shell's Pid
    
    2> spawn(fun() -> ets:new(my_table, [named_table, public]), receive X -> ok end end).
    <0.35.0>    % the spawned process's Pid
    
    3> ets:insert(my_table, {a, b}).
    true
    
    4> 1/0.
    ** exception error: bad argument in an arithmetic expression
         in operator  '/'/2
            called as 1 / 0
    5> self().
    <0.38.0>   % shell's reborn, with a different Pid
    
    6> ets:insert(my_table, {c, d}).
    true
    7> ets:tab2list(my_table).
    [{c,d},{a,b}]    % table did survive the shell restart
    
    8> pid(0,35,0) ! bye_bye.
    bye_bye
    9> ets:info(my_table).   
    undefined