1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 10:07:45 +03:00
mal/r/types.r

50 lines
886 B
R
Raw Normal View History

2014-11-01 23:54:48 +03:00
..types.. <- TRUE
# General type related functions
concat <- function(...) {
paste(..., collapse="", sep="")
}
# Errors/exceptions
thrown_error = new.env()
thrown_error$val = NULL
throw <- function(obj) {
thrown_error$val = obj
stop("<mal_exception>")
}
get_error <- function(e) {
estr <- e$message
if (estr == "<mal_exception>") {
err <- thrown_error$val
thrown_error$val <- NULL
err
} else {
estr
}
}
# Lists
new.list <- function(...) {
lst <- list(...)
class(lst) <- "List"
lst
}
new.listl <- function(lst) {
class(lst) <- "List"
lst
}
.list_q <- function(obj) "List" == class(obj)
# Vectors
new.vector <- function(...) {
lst <- list(...)
class(lst) <- "Vector"
lst
}
new.vectorl <- function(lst) {
class(lst) <- "Vector"
lst
}
.vector_q <- function(obj) "Vector" == class(obj)