ets weirdness when using -run

Chris Pressey <>
Tue Jun 18 23:24:13 CEST 2002


I have a program that uses a public, named ets table like so:


-module(eg).
-export([start/1, new/1]).

start(Key) ->
  ets:new(my_ets, [public, named_table]),
  io:fwrite("~p~n", [ets:info(my_ets)]),
  start_new(lists:flatten(Key)).

start_new(Key) ->
  spawn(?MODULE, new, [Key]).

new(Key) ->
  io:fwrite("~p~n", [ets:info(my_ets)]),
  case ets:lookup(my_ets, Key) of
    [_] ->
       io:fwrite("Already in database~n");
    _ ->
       io:fwrite("Not yet in database~n")
  end.


Here is what happens when I run it from the Erlang shell:


kallisti# erl
Erlang (BEAM) emulator version 5.1.1 [source]

Eshell V5.1.1  (abort with ^G)
1> eg:start("Key").
{{memory,276},
 {owner,<0.23.0>},
 {name,my_ets},
 {size,0},
 {},
 {named_table,true},
 {type,set},
 {keypos,1},
 {protection,public}}
{{memory,276},
 {owner,<0.23.0>},
 {name,my_ets},
 {size,0},
 {},
 {named_table,true},
 {type,set},
 {keypos,1},
 {protection,public}}
<0.30.0>
Not yet in database
2> 


But here is what happens when I run it from the command line:


kallisti# erl -run eg start Key
Erlang (BEAM) emulator version 5.1.1 [source]

Eshell V5.1.1  (abort with ^G)
1> {{memory,276},
 {owner,<0.1.0>},
 {name,my_ets},
 {size,0},
 {},
 {named_table,true},
 {type,set},
 {keypos,1},
 {protection,public}}
undefined

=ERROR REPORT==== 18-Jun-2002::16:22:00 ===
Error in process <0.30.0> with exit value:
{badarg,[{ets,lookup,[my_ets,"Key"]},{eg,new,1}]}


Any thoughts on what I might be doing wrong to make my_ets just vanish
like that?

-Chris



More information about the erlang-questions mailing list