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 3395144
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:15:18+00:00 2026-05-18T04:15:18+00:00

From Erlang Programming by Cesarini exercise 3-2 As I go through Erlang Programming I

  • 0

From “Erlang Programming” by Cesarini exercise 3-2

As I go through “Erlang Programming” I get weird list creation issues. From exercise 3-2 I wrote two similar functions.

create( 0 ) -> [];
create( N ) when N > 0 -> [ N | create( N-1 ) ].

reverse_create( 0 ) -> [];
reverse_create( N ) when N > 0 -> [ reverse_create( N-1 ) | N ].

so create(3) generates as I’d expect.

exercise3:create(3).
[3,2,1]

but reverse_create does not generate the list I expect.

exercise3:reverse_create(3).
[[[[]|1]|2]|3]

What do I need to change so that reverse_create(3) returns [1,2,3]? Thanks for explaining.

  • 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-05-18T04:15:19+00:00Added an answer on May 18, 2026 at 4:15 am

    reverse_create returns a list and you using that as head element to create the list which is resulting in nested lists. Try this solution:

    reverse_create( 0 ) -> [];
    reverse_create( N ) when N > 0 -> reverse_create( N-1 ) ++ [N].
    

    EDIT: A much better implementation would be:

    reverse_create2(N) -> reverse_create_helper(N, []).
    
    reverse_create_helper(0, Acc) ->
        Acc;
    reverse_create_helper(N, Acc) ->
        reverse_create_helper(N-1, [N|Acc]).
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From page 90 of Erlang Programming by Cesarini and Thomson, there is an example
I'm going through Cesarini and Thompson's Erlang Programming (O'Reilly) and I made a solution
Read (skimmed enough to get coding) through Erlang Programming and Programming Erlang . One
Today I was doing the thread ring exercise from the Programming Erlang book and
Erlang's Characteristics From Erlang Programming (2009): Erlang concurrency is fast and scalable. Its processes
From time to time I get a System.Threading.ThreadStateException when attempting to restart a thread.
From what I can gather, there are three categories: Never use GET and use
I have Programming Erlang book already and I use http://www.erlang.org/ site. But I can't
I'm playing with the distributed programming tutorial from the 5.4 documentation, and have run
I'm reading Programming Erlang by Joe Armstrong(Pragmatic Bookshelf) . In name_server.erl source code on

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.