Last active
July 17, 2017 02:21
-
-
Save josephan/d5fe16f50de1aa1e4aadb703b62373fb to your computer and use it in GitHub Desktop.
Computer Science 61A - Lecture 1: functional programming 1
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
defmodule Lecture1 do | |
def add(list), do: add(list, 0) | |
defp add([h | t], acc), do: add(t, acc + h) | |
defp add([], acc), do: acc | |
def mult(list), do: mult(list, 1) | |
defp mult([h | t], acc), do: mult(t, acc * h) | |
defp mult([], acc), do: acc | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment