implement memoize expression