Created
July 25, 2022 21:38
-
-
Save DominikRafacz/e54cc8d3626f14c5de6f6038b8d09645 to your computer and use it in GitHub Desktop.
Curious matching fun case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun_wants_num <- function(x) { | |
x + 1 | |
} | |
fun_wants_fun_but_fails <- function(fun) { | |
fun(1) | |
} | |
fun_wants_fun <- function(fun) { | |
fun <- match.fun(fun) | |
fun(2) | |
} | |
g09 <- function(x, ...) { | |
exp(x) | |
} | |
g10 <- function() { | |
g09 <- 10 | |
print(g09 + 3) # used as a value | |
print(g09(3)) # used as a function | |
print(fun_wants_num(g09)) # used as a value | |
print(fun_wants_fun(g09)) # used as a function | |
print(fun_wants_fun_but_fails(g09)) # used as a value - error! | |
} | |
g10() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment