Skip to content

Instantly share code, notes, and snippets.

@josephan
Last active Jul 17, 2017
Embed
What would you like to do?
Computer Science 61A - Lecture 1: functional programming 1
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