More complete implementation of the attr function.