Skip to content

Instantly share code, notes, and snippets.

@josephan
Last active July 17, 2017 02:21
Show Gist options
  • Save josephan/d5fe16f50de1aa1e4aadb703b62373fb to your computer and use it in GitHub Desktop.
Save josephan/d5fe16f50de1aa1e4aadb703b62373fb to your computer and use it in GitHub Desktop.
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