| 1 | ..core.. <- TRUE |
| 2 | |
| 3 | if(!exists("..types..")) source("types.r") |
| 4 | if(!exists("..printer..")) source("printer.r") |
| 5 | |
| 6 | |
| 7 | # String functions |
| 8 | |
| 9 | pr_str <- function(...) .pr_list(..., print_readably=TRUE, join=" ") |
| 10 | |
| 11 | str <- function(...) .pr_list(..., print_readably=FALSE, join="") |
| 12 | |
| 13 | prn <- function(...) { |
| 14 | cat(.pr_list(..., print_readably=TRUE, join=" ")); cat("\n") |
| 15 | nil |
| 16 | } |
| 17 | |
| 18 | println <- function(...) { |
| 19 | cat(.pr_list(..., print_readably=FALSE, join=" ")); cat("\n") |
| 20 | nil |
| 21 | } |
| 22 | |
| 23 | # Sequence functions |
| 24 | cons <- function(a,b) { |
| 25 | new_lst <- append(list(a), b) |
| 26 | class(new_lst) <- "List" |
| 27 | new_lst |
| 28 | } |
| 29 | |
| 30 | do_concat <- function(...) { |
| 31 | new_lst <- list() |
| 32 | for(l in list(...)) { |
| 33 | new_lst <- append(new_lst, l) |
| 34 | } |
| 35 | class(new_lst) <- "List" |
| 36 | new_lst |
| 37 | } |
| 38 | |
| 39 | core_ns <- list( |
| 40 | "="=function(a,b) .equal_q(a,b), |
| 41 | |
| 42 | "pr-str"=pr_str, |
| 43 | "str"=str, |
| 44 | "prn"=prn, |
| 45 | "println"=println, |
| 46 | "read-string"=function(str) read_str(str), |
| 47 | "slurp"=function(path) readChar(path, file.info(path)$size), |
| 48 | "<"=function(a,b) a<b, |
| 49 | "<="=function(a,b) a<=b, |
| 50 | ">"=function(a,b) a>b, |
| 51 | ">="=function(a,b) a>=b, |
| 52 | "+"=function(a,b) a+b, |
| 53 | "-"=function(a,b) a-b, |
| 54 | "*"=function(a,b) a*b, |
| 55 | "/"=function(a,b) a/b, |
| 56 | |
| 57 | "list"=function(...) new.list(...), |
| 58 | "list?"=function(a) .list_q(a), |
| 59 | "empty?"=function(a) .sequential_q(a) && length(a) == 0, |
| 60 | "count"=function(a) length(a), |
| 61 | |
| 62 | "cons"=cons, |
| 63 | "concat"=do_concat |
| 64 | ) |