Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8077385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:27:46+00:00 2026-06-05T15:27:46+00:00

I am not sure how to call a local function in a module so

  • 0

I am not sure how to call a local function in a module so that after the code change the latest version of the code will be used. See the following example:

1  -module(test).
2
3  -export([start/0, call/1]).
4  -export([loop/0, add/1]).
5
6  start() ->
7      register(foo, spawn(test, loop, [])).
8
9  call(X) ->
10     foo ! {self(), X},
11     receive
12         Y -> Y
13 end.
14
15 loop() ->
16     receive
17         {Pid, Z} -> Pid ! add(Z)
18     end,
19     loop().
20
21 add(N) ->
22     N + 1.

The function that will be changed is add/1. In order to use the latest version of the function, the call of add/1 (line 17) should be fully qualified function call
{Pid, Z} -> Pid ! ?MODULE:add(Z).
When I try it, I get this:

1> c(test). 
{ok,test}
2> test:start(). 
true
3> test:call(1).
2

line 22 changed to N + 2

4> c(test).     
{ok,test}
5> test:call(1).
3

line 22 changed again to N + 3

6> c(test).     
{ok,test}
7> test:call(1).
** exception error: bad argument
    in function  test:call/1 (test.erl, line 10)

Why do I get this error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:27:48+00:00Added an answer on June 5, 2026 at 3:27 pm

    I believe that you need to eventually call the fully qualified version of the loop/0 function instead of the add/1 function in order to load and use the new module. The code loading mechanism is prepared to handle two running versions of a module at once, and your example with N+3 is the third load of the module — and the first versions is forcibly removed.

    Try instead this loop:

    15 loop() ->
    16     receive
    17         {Pid, Z} -> Pid ! add(Z)
    18     end,
    19     ?MODULE:loop().
    

    I’ve changed it to reload the newest version on next execution of the loop/0.

    I believe more common is to use a reload message or similar that will directly call the main loop explicitly, to avoid the overhead of constantly reloading the module on every request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I see there is a API call for Frienships/Show, but I am not sure
Not sure what to call it, but a combined solution for starting servers/logging/consoles/development would
I'm not sure what to call this question, since it involves a variety of
Is there is a library for invoking math symbols/formula(not sure what to call), which
on the ipad, when in portrait(not sure if you call it this) the [[self
I have never thought about until recently, but I'm not sure why we call
Not sure what I'm doing wrong but I can't get my JQuery AJAX call
I'm not sure if this is even what you call it, but basically, I
I'm not sure this is possible, but in ruby, you can dynamically call a
I am trying to add a new payment module into Magento. However, even after

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.