CCRefSourceHelpers for references
Update the reference's content with the given function.
incr_then_get r increments r and returns its new value, think ++r.
get_then_incr r increments r and returns its old value, think r++.
protect r x f sets r := x; calls f(); restores r to its old value; and returns the result of f().