make various code aware of repeat, may miss some
prepare adding :repeat support in cs-gen
also use function to encapsulate common
functionality in fold-default