Created
July 21, 2008 20:27
-
-
Save anonymous/116 to your computer and use it in GitHub Desktop.
Revisions
-
There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ ;; 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)))