This seems wrong: suppose all functions called return NotImplemented.
Instead, check if *result is not null, and set it to NULL before the loop.