new_point <- function(x, y) {
structure(list(x = x, y = y), class = "Point")
}
# Unary operator: swaps the coordinates
"!.Point" <- function(e1) {
new_point(e1$y, e1$x)
}
p <- new_point(1, 3)
# A new point: p itself is not changed
swapped <- !p
cat("p =", p$x, p$y, "\n")
cat("swapped =", swapped$x, swapped$y, "\n")