Skip to content

Instantly share code, notes, and snippets.

@apbarrero
Created June 27, 2017 20:53
Show Gist options
  • Save apbarrero/e48688ee07e9c37afe7a1aa43a85217a to your computer and use it in GitHub Desktop.
Save apbarrero/e48688ee07e9c37afe7a1aa43a85217a to your computer and use it in GitHub Desktop.
Defining functions over lists in practice
-module(lists1).
-export([product/1, maximum/1]).
product(Xs) -> product(Xs, 1).
product([], P) -> P;
product([X|Xs], P) -> product(Xs, X*P).
maximum([X|Xs]) -> maximum(Xs, X).
maximum([X|[]], M) -> max(X, M);
maximum([X|Xs], M) -> maximum(Xs, max(X, M)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment