Commit | Line | Data |
---|---|---|
01feedfe JM |
1 | ..core.. <- TRUE |
2 | ||
3 | if(!exists("..types..")) source("types.r") | |
4 | if(!exists("..printer..")) source("printer.r") | |
5 | ||
6 | ||
c30efef4 JM |
7 | # String functions |
8 | ||
01feedfe JM |
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 | ||
c30efef4 JM |
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 | ||
01feedfe JM |
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, | |
c30efef4 JM |
46 | "read-string"=function(str) read_str(str), |
47 | "slurp"=function(path) readChar(path, file.info(path)$size), | |
01feedfe JM |
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, | |
c30efef4 | 60 | "count"=function(a) length(a), |
01feedfe | 61 | |
c30efef4 JM |
62 | "cons"=cons, |
63 | "concat"=do_concat | |
01feedfe | 64 | ) |