pattern-matching version of paramcount function