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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:46:18+00:00 2026-06-11T19:46:18+00:00

I started to learn some Erlang and right now I am stuck with following

  • 0

I started to learn some Erlang and right now I am stuck with following “problem”.

I know how recursion works and I am aware of the basics of HigherOrderFunctions.

So to get more into the whole concept I implemented “lists:all/2” with the usage of fold myself:

fold(_, Start, []) -> Start;
fold(F, Start, [H|T]) -> fold(F, F(H, Start), T).

all(Pred, L) ->
    F = fun(H, ToF) ->
        case Pred(H) of
            true -> ToF;
            false -> false
        end
    end,
    fold(F, true, L).

I know this version does not care about empty lists, but that is not what bothers me. I can’t figure out why it works how it does.

When I use my list [1,2,3] and set the Pred to “fun(X) when X == 3 -> true; (_) -> false end” it obviously returns “false”. But why? if I work this through on paper as last call before something is returned I get:

fold(F, F(H, Start), T)

Where F is Pred and F(H, Start) returns “true” because the last element is 3 and T is an empty list [].

So when I get this right, the last call should be fold(_, true, []) and should therefore return “true” which it doesn’t.

Am I missing something here or do I get anything wrong when it comes to evaluating the last expression? Does this function somehow use logical AND on all the returns of “Pred”?

  • 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-11T19:46:20+00:00Added an answer on June 11, 2026 at 7:46 pm

    Basically, you are right about the last call, but when doing your analysis, you’ve substituted true for Start value, where in fact this value is false:

    fold(F, true, [1,2,3])
    

    evaluates to:

    fold(F, true, [1|[2,3]]) -> fold(F, F(1, true), [2,3])
    

    which in turns evaluates to:

    fold(F, false, [2|3]) -> fold(F, F(2, false) [3])
    

    which in turns evaluates to:

    fold(F, false, [3|[]]]) -> fold(F, F(3, false), [])
    

    which evaluates to:

    fold(_, false, []) -> false
    

    Because in last call Pred is true, and you are returning ToF, which is false.

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

Sidebar

Related Questions

I know some scala and started to learn lift. As long as it works
I'm recently started to learn Twisted framework and now looking for some cheat sheets/reference
I just started to learn about mod rewrite process. Now, I got some problems
I've just started my adventure with Cassandra database. I've managed to learn some basics
I'm getting started with OpenGL ES on Android and I'd looking to learn some
I recently started to learn how to use openCL to speed up some part
When I started to learn about WPF and MVVM recently, I came across some
I'm trying to learn the python scripting . Being some body who started coding
I am newbie trying to learn some code. I am following the tutorial on
i want to learn entity framework. i started with some EF tutorials and i

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.