search for: factorial_tr_3

Displaying 6 results from an estimated 6 matches for "factorial_tr_3".

Did you mean: factorial_tr_1
2018 Feb 14
0
Parallel assignments and goto
...riable (or variables) -- see below. I wouldn't be surprised if someone can come up with a faster implementation, but I suspect that the overhead of function calls will be hard to overcome. BTW, a version of my passign() that uses mapply() in place of a for loop (not shown) is even slower. > factorial_tr_3 <- function (n, acc = 1) { + repeat { + if (n <= 1) + return(acc) + else { + passign(n = n - 1, acc = acc * n) + next + } + } + } > microbenchmark::microbenchmark(factorial(100), + factorial_tr_1(100), + factorial_tr_2(1...
2018 Feb 11
4
Parallel assignments and goto
...t containing the bound variables and then evaluate this using `eval` or `with`, but in either case, a call to `next` will not work in such a context. The expression will be evaluated inside `bind` or `with`, and not in the `list_lenght` function. A version that *will* work, is something like this factorial_tr_3 <- function (n, acc = 1) { .tailr_env <- rlang::get_env() .tailr_frame <- rlang::current_frame() repeat { if (n <= 1) rlang::return_from(.tailr_frame, acc) else { rlang::env_bind(.tailr_env, n = n - 1, acc = acc * n) rlan...
2018 Feb 11
0
Parallel assignments and goto
...nd variables and then evaluate this using `eval` or `with`, but in either case, a call to `next` will not work in such a context. The expression will be evaluated inside `bind` or `with`, and not in the `list_lenght` function. > > A version that *will* work, is something like this > > factorial_tr_3 <- function (n, acc = 1) > { > .tailr_env <- rlang::get_env() > .tailr_frame <- rlang::current_frame() > repeat { > if (n <= 1) > rlang::return_from(.tailr_frame, acc) > else { > rlang::env_bind(.tailr_env, n = n - 1...
2018 Feb 26
0
Parallel assignments and goto
...ound variables and then evaluate this using `eval` or `with`, but in either case, a call to `next` will not work in such a context. The expression will be evaluated inside `bind` or `with`, and not in the `list_lenght` function. > > A version that *will* work, is something like this > > factorial_tr_3 <- function (n, acc = 1) > { > .tailr_env <- rlang::get_env() > .tailr_frame <- rlang::current_frame() > repeat { > if (n <= 1) > rlang::return_from(.tailr_frame, acc) > else { > rlang::env_bind(.tailr_env, n = n - 1, acc = acc * n) > rlang::return_to(.tailr_f...
2018 Feb 27
2
Parallel assignments and goto
...hen evaluate this using `eval` or `with`, but in either case, a call to `next` will not work in such a context. The expression will be evaluated inside `bind` or `with`, and not in the `list_lenght` function. > > > > A version that *will* work, is something like this > > > > factorial_tr_3 <- function (n, acc = 1) > > { > > .tailr_env <- rlang::get_env() > > .tailr_frame <- rlang::current_frame() > > repeat { > > if (n <= 1) > > rlang::return_from(.tailr_frame, acc) > > else { > > rlang::env_bind(.tailr_env, n = n - 1, acc =...
2018 Feb 27
0
Parallel assignments and goto
...gt; `with`, but in either case, a call to `next` will not work in such a > context. The expression will be evaluated inside `bind` or `with`, and not > in the `list_lenght` function. > > > > > > A version that *will* work, is something like this > > > > > > factorial_tr_3 <- function (n, acc = 1) > > > { > > > .tailr_env <- rlang::get_env() > > > .tailr_frame <- rlang::current_frame() > > > repeat { > > > if (n <= 1) > > > rlang::return_from(.tailr_frame, acc) > > > else { > > > rlan...