Created
June 27, 2017 20:53
-
-
Save apbarrero/e48688ee07e9c37afe7a1aa43a85217a to your computer and use it in GitHub Desktop.
Defining functions over lists in practice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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