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

  • Home
  • SEARCH
  • 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 40535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:02:20+00:00 2026-05-10T15:02:20+00:00

I’m going through the problems on projecteuler.net to learn how to program in Erlang,

  • 0

I’m going through the problems on projecteuler.net to learn how to program in Erlang, and I am having the hardest time creating a prime generator that can create all of the primes below 2 million, in less than a minute. Using the sequential style, I have already written three types of generators, including the Sieve of Eratosthenes, and none of them perform well enough.

I figured a concurrent Sieve would work great, but I’m getting bad_arity messages, and I’m not sure why. Any suggestions on why I have the problem, or how to code it properly?

Here’s my code, the commented out sections are where I tried to make things concurrent:

 -module(primeserver). -compile(export_all).  start() ->     register(primes, spawn(fun() -> loop() end)).  is_prime(N) -> rpc({is_prime,N}).  rpc(Request) ->     primes ! {self(), Request},     receive         {primes, Response} ->             Response     end.  loop() ->     receive         {From, {is_prime, N}} ->             if                 N  From ! {primes, false};                 N =:= 2 -> From ! {primes, true};                 N rem 2 =:= 0 -> From ! {primes, false};                 true ->                     Values = is_not_prime(N),                     Val = not(lists:member(true, Values)),                     From ! {primes, Val}             end,             loop()     end.  for(N,N,_,F) -> [F(N)]; for(I,N,S,F) when I + S  [F(I)|for(I+S, N, S, F)]; for(I,N,S,F) when I + S =:= N -> [F(I)|for(I+S, N, S, F)]; for(I,N,S,F) when I + S > N -> [F(I)].  get_list(I, Limit) ->     if         I              [I*A || A              []     end.  is_not_prime(N) ->     for(3, N, 2,          fun(I) ->              List = get_list(I,trunc(N/I)),             lists:member(N,lists:flatten(List))         end         ).      %%L = for(1,N, fun() -> spawn(fun(I) -> wait(I,N) end) end),     %%SeedList = [A || A       %%      lists:foreach(fun(X) ->     %%              Pid ! {in_list, X}      %%                end, SeedList)     %%        end, L).  %%wait(I,N) -> %%  List = [I*A || A  lists:member(X,List) %%  end. 
  • 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. 2026-05-10T15:02:20+00:00Added an answer on May 10, 2026 at 3:02 pm

    The ‘badarity’ error means that you’re trying to call a ‘fun’ with the wrong number of arguments. In this case…

    %%L = for(1,N, fun() -> spawn(fun(I) -> wait(I,N) end) end),

    The for/3 function expects a fun of arity 1, and the spawn/1 function expects a fun of arity 0. Try this instead:

    L = for(1, N, fun(I) -> spawn(fun() -> wait(I, N) end) end), 

    The fun passed to spawn inherits needed parts of its environment (namely I), so there’s no need to pass it explicitly.

    While calculating primes is always good fun, please keep in mind that this is not the kind of problem Erlang was designed to solve. Erlang was designed for massive actor-style concurrency. It will most likely perform rather badly on all examples of data-parallel computation. In many cases, a sequential solution in, say, ML will be so fast that any number of cores will not suffice for Erlang to catch up, and e.g. F# and the .NET Task Parallel Library would certainly be a much better vehicle for these kinds of operations.

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

Sidebar

Ask A Question

Stats

  • Questions 172k
  • Answers 173k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This seems like it would work: get the time since… May 12, 2026 at 2:35 pm
  • Editorial Team
    Editorial Team added an answer Sorry, I'm new to this site, and I don't see… May 12, 2026 at 2:35 pm
  • Editorial Team
    Editorial Team added an answer WAV and AIFF often (usually?) contain PCM, so what's the… May 12, 2026 at 2:35 pm

Related Questions

In order to apply a triggered animation to all ToolTip s in my app,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.