Skip to content

Instantly share code, notes, and snippets.

Created July 21, 2008 20:27
Show Gist options
  • Save anonymous/116 to your computer and use it in GitHub Desktop.
Save anonymous/116 to your computer and use it in GitHub Desktop.
undefined
;; Issac Trotts' demonstration of pattern matching in Nu
(function people-to-string (people)
(match people
(() "no people")
((p1) "one person: #{p1}")
((p1 p2) "two people: #{p1} and #{p2}")
(else "too many people: #{(people length)}")))
(assert_equal "no people"
(people-to-string '()))
(assert_equal "one person: Tim"
(people-to-string '(Tim)))
(assert_equal "two people: Tim and Matz"
(people-to-string '(Tim Matz)))
(assert_equal "too many people: 3"
(people-to-string '(Tim Guido Matz)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment