repeat_and_stack function

Repeat an expression multiple times and (optionally) stack the results.