tail-recursive format/3