[erlang-questions] Current function undefined as displayed by i().
Trond Endrestøl
Trond.Endrestol@REDACTED
Thu Dec 3 12:32:51 CET 2015
Hi,
I'm new to the list and new to Erlang.
I'm running:
FreeBSD 10.2-STABLE #0 r291578: Tue Dec 1 14:32:16 CET 2015 amd64
Erlang is erlang-18.1.5,3 from FreeBSD's ports collection
(lang/erlang):
Erlang/OTP 18 [erts-7.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:true] [dtrace]
Eshell V7.1
I came across a puzzle:
I have an Erlang process spawned with a function of arity 0.
Running the shell command i() gives this (abbreviated) output.
Pid Initial Call Heap Reds Msgs
Registered Current Function Stack
<0.42.0> mathserver:loop/0 987 10679 0
mathserver undefined 0
Here's start/0 from my module mathserver:
start() ->
Pid = erlang:spawn(?MODULE, loop, []),
erlang:register(?MODULE, Pid), % Local name register
global:register_name(?MODULE, Pid). % Global name register
loop/0 in this module consists mainly of a receive statement, spawning
new processes when it recognises a particular message.
While googling for "erlang current function undefined", I tried the
sample code from
http://stackoverflow.com/questions/12585612/erlang-undefined-function.
I made some slight modifications to the code, limited to a better
module name, the use of the ?MODULE macro as appropriate, and a call
to global:register_name/2.
In this case the bcast_server:process_request/1 is spawned with an
empty list in the argument list, i.e. [[]].
start() ->
ServerPid = erlang:spawn(?MODULE, process_requests, [ [] ]),
erlang:register(?MODULE, ServerPid),
global:register_name(?MODULE, ServerPid).
Running i() produces this (abbreviated) output:
Pid Initial Call Heap Reds Msgs
Registered Current Function Stack
<0.57.0> bcast_server:process_requests/1 233 1 0
bcast_server bcast_server:process_requests/1 3
process_requests/1 is similar to my own loop/0. The only difference is
arity of 0 versus arity of 1, i.e. non-zero.
A named Erlang node bears no difference from an anonymous Erlang node.
Can someone please explain why "current function" is undefined in one
instance and defined in another?
--
----------------------------------------------------------------------
Trond Endrestøl | Trond.Endrestol@REDACTED
ACM, NAS, NUUG, SAGE, USENIX | FreeBSD 10.2-S & Alpine 2.20
More information about the erlang-questions
mailing list