R/return_else.R

Defines functions fn g h

library(rlang)

# Passing fn() evaluation frame to g():
fn <- function(early = F) {
  fn_env <- current_env()
  if(early)
    g(fn_env)
  stop("expected return prior here (fn) in call to (g)")
}

g <- function(env){
  return_from(env, "sig-g: return early from fn")
  stop("expected return from 1st (fn) in call to next (h)")

}

# Here we return from fn() with a new return value:
h <- function(env){
  return_from(env, "sig-h: return early from fn")
  stop("expected return from 1st (fn) in prior eval from here")
}
fn()
bfatemi/ninjar documentation built on Sept. 8, 2019, 7:37 p.m.