new_counter <- function(count) {
structure(list(count = count),
class = "Counter")
}
report <- function(counter) {
UseMethod("report")
}
# Вызывается только ради вывода
report.Counter <- function(counter) {
cat("count =", counter$count, "\n")
}
counter <- new_counter(11)
# Без return: вызов даёт NULL
result <- report(counter)
# count = 11
no_value <- is.null(result)
# no_value = TRUE
cat("no_value =", no_value, "\n")