Do we have a full understanding if in case of vectorized leap
function in R short-circuit operations work as well?
I suspect that only &&
and ||
work in short-circuit but &
and |
do not - how is it?
I made a test, please try it out and reason with me if I am correct:
paused_TRUE <- function() {
Sys.sleep(2)
TRUE
}
c(TRUE, TRUE, TRUE) | c(FALSE, FALSE, paused_TRUE())
TRUE || paused_TRUE()
TRUE | paused_TRUE()
c(FALSE, FALSE, FALSE) & c(TRUE, FALSE, paused_TRUE())
FALSE && paused_TRUE()
FALSE & paused_TRUE()
Observe how vectorised version pause execution and simple ones do not, making short circuit. I think if we advise vectorised version in R for leap exercise we cannot talk about short circuiting at the same time. So some changes needed in mentoring guide.
WDYT?