re-implement two built-in func with recursion