calc: a pattern matching solution