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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:41:33+00:00 2026-05-28T20:41:33+00:00

I have an empty list, and, in a special case, want to append a

  • 0

I have an empty list, and, in a special case, want to append a tuple to the list. How can I do that?

I tried several approaches:

case ReqFilePath of
    "style.css" ->
        ResponseHeaders = [{"Content-Type", "text/css"}];
    _Else ->
        ResponseHeaders = []
end,


case filelib:is_file(File) of
    true ->
        {ok, Content} = file:read_file(File),
        {output, Content, ResponseHeaders}; % Complains ResponseHeaders is not safe
    false ->
        not_found
end.

This does not work either, since the variable is already set. When I initialize ResponseHeaders = [] first, and then try to add a value to it

ResponseHeaders = lists:append(ResponseHeaders, [{"Content-Type", "text/css"}]);

I get a match error. How do you do this normally in Erlang?

  • 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-28T20:41:34+00:00Added an answer on May 28, 2026 at 8:41 pm

    The usual way to do this in erlang is just to use another variable:

    ResponseHeaders = [{"Content-Type", "text/css"}],
    [...]
    ResponseHeaders2 = ResponseHeaders ++ [{new_thing}]
    

    Or you could make a function that builds the ResponseHeaders for you:

    ResponseHeaders = build_headers(ReqFilePath).
    
    build_headers("skin.css") -> [{"Content-Type", "text/css"}];
    build_headers(_) -> [].
    

    Don’t forget to change your mindset to the erlang way! 😉

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

Sidebar

Related Questions

If I have an empty tag: <tag/> How can I add text so that
I have an empty unordered list in my design. Now I want to add
How would one do this? I have tried creating a new, empty list, then
i currently have an empty drop down list that I would like to fill
I have a single page jQuery mobile application that consists of several list views
I have to make a function that takes an empty list as first argument
I have a problem with random and arrays. I have a list empty list
I have a list which is dynamically built, but there are empty list items
I have a list (tmpList), which looks like this: $op [1] empty $termset $termset$field
Android empty list layout Whatever I do, I can't get the empty tag 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.