library(proto)

stack <- proto(expr = {
   l <- list()
   empty <- function(.) length(.$l) == 0
   push <- function(., x) 
   {
      .$l <- c(list(x), .$l)
      print(.$l)
      invisible()
   }
   pop <- function(.) 
   {
      if(.$empty()) stop("can't pop from an empty list")
      .$l[[1]] <- NULL
      print(.$l)
      invisible()
   }
})

stack$empty()

stack$push(3)


stack$push("abc")




stack$push(matrix(1:6, nrow=2))








stack$empty()

stack$pop()

[1] "abc"


stack$pop()


stack$pop()

stack$pop()