[erlang-questions] array search problem

Fred Hebert mononcqc@REDACTED
Fri Jan 30 18:18:56 CET 2015

Agh, I ended up repeating 'base case' everywhere in my recursion
explanation. My bad.

Here's the fixed version:

On 01/30, Fred Hebert wrote:
> Recursive functions have two main kinds of clauses (I'm going with an
> informal definition here): base cases, and the regular case. The base
> case is whenever recursion cannot proceed further. The regular case is when
> you can proceed further.
> To search elements in a list, your base case will therefore be '[]', the
> empty list, where you can't search further.
> The regular case will be the other [Element | Rest].
> So your function to search in a DB? To avoid giving you the answer, you
> know that if you can't look further, you haven't found the element.
> Therefore,
>     lookup(Element, []) ->
>         {error, not_found};
>     lookup(Element, [??? | RestOfList]) ->
>         ???.
> Can you fill in the blanks for the regular case? If not, go back a few
> chapters. There's no shame in doing that and making sure you
> understand things right before moving on to more difficult topics.

Sorry about that.

More information about the erlang-questions mailing list