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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:47:54+00:00 2026-05-12T23:47:54+00:00

I am learning Erlang and I am trying to create a very sample blog

  • 0

I am learning Erlang and I am trying to create a very sample blog program. However my mind currently is trapped in the OO world (var p = new Post(); p.Title = “”; p.Save();). I would like to understand some basic thinkings in Erlang. Instead of creating Post object what I should do in terms of data structure (p.Title, p.DateCreated, p.Body)? Should I be using tuple? I would like to understand the recommended way in doing such things (in both Erlang specific and or Functional Programming specific). Or is what I am doing fundamentally wrong in either Erlang or FP?

Requirement (in OO terms, not sure how to explain in FP terms yet ^_^):

  1. create Post object (id, title, date_created, body, IList)
  2. create Comment object (id, post_id, created_by (name as string), date_created)
  3. one Post can have multiple comments
  4. post.AddComment(Comment)

Thanks.

Updated:
I am not looking for specific way of doing OOP in Erlang unless it’s the recommended way. I am looking for standard/recommended way of doing what’s described in the question, however I am not trying to replicate OOP in Erlang.

  • 1 1 Answer
  • 1 View
  • 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-12T23:47:54+00:00Added an answer on May 12, 2026 at 11:47 pm

    I would use records:

    -record(post, {title, date_created, body, comments = []}).
    -record(comment, {created_by, date_created, content}).
    

    Then if you want to use mnesia as database:

    Post = #post{title = "", body = "", date_created = erlang:universaltime()},
    mnesia:transaction(fun() -> mnesia:write(Post) end).
    

    To add a comment:

    Comment = #comment{created_by = "", content = "", date_created = erlang:universaltime()},
    mnesia:transaction(fun() ->
        [Post] = mnesia:read(post, Title),
        PostWithNewComment = Post#post{comments = [Comment | Post#post.comments]},
        mnesia:write(PostWithNewComment)
    end).
    

    I haven’t tested the code, but this is what I would do. Also I assumed that each title is unique.

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

Sidebar

Related Questions

I have just started learning Erlang and am trying out some Project Euler problems
I am currently learning Erlang Can SO users give interesting examples of any of
I’ve started learning Erlang a few days ago and it’s definitely a very interesting
I'm in the process of learning Erlang. As an exercise I picked up the
Learning WPF nowadays. Found something new today with .Net dependency properties. What they bring
Im learning lisp and im pretty new at this so i was wondering... if
I'm learning about table design in SQL and I'm wonder how to create a
While I'm learning a new language, I'll typically put lots of silly println's to
I have been learning Erlang, but also I'm keeping my eyes open to other
Since a few months I've been learning Erlang, and now it was time to

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.