aboutsummaryrefslogtreecommitdiff
path: root/r/core.r
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-11-03 20:02:09 -0600
committerJoel Martin <github@martintribe.org>2015-01-09 16:16:43 -0600
commitc30efef469e22c8ba345a72c058c28362e57b746 (patch)
treee2b9a4252c7771dd8f4554c4b248d370b66e0ae3 /r/core.r
parent01feedfe22a381c6b6ca79bdf0db798aa08c4104 (diff)
downloadmal-c30efef469e22c8ba345a72c058c28362e57b746.tar.gz
mal-c30efef469e22c8ba345a72c058c28362e57b746.zip
R: add step6_file and step7_quote
Change symbols to be special class.
Diffstat (limited to 'r/core.r')
-rw-r--r--r/core.r24
1 files changed, 23 insertions, 1 deletions
diff --git a/r/core.r b/r/core.r
index a59dfb6..47800ac 100644
--- a/r/core.r
+++ b/r/core.r
@@ -4,6 +4,8 @@ if(!exists("..types..")) source("types.r")
if(!exists("..printer..")) source("printer.r")
+# String functions
+
pr_str <- function(...) .pr_list(..., print_readably=TRUE, join=" ")
str <- function(...) .pr_list(..., print_readably=FALSE, join="")
@@ -18,6 +20,22 @@ println <- function(...) {
nil
}
+# Sequence functions
+cons <- function(a,b) {
+ new_lst <- append(list(a), b)
+ class(new_lst) <- "List"
+ new_lst
+}
+
+do_concat <- function(...) {
+ new_lst <- list()
+ for(l in list(...)) {
+ new_lst <- append(new_lst, l)
+ }
+ class(new_lst) <- "List"
+ new_lst
+}
+
core_ns <- list(
"="=function(a,b) .equal_q(a,b),
@@ -25,6 +43,8 @@ core_ns <- list(
"str"=str,
"prn"=prn,
"println"=println,
+ "read-string"=function(str) read_str(str),
+ "slurp"=function(path) readChar(path, file.info(path)$size),
"<"=function(a,b) a<b,
"<="=function(a,b) a<=b,
">"=function(a,b) a>b,
@@ -37,6 +57,8 @@ core_ns <- list(
"list"=function(...) new.list(...),
"list?"=function(a) .list_q(a),
"empty?"=function(a) .sequential_q(a) && length(a) == 0,
- "count"=function(a) length(a)
+ "count"=function(a) length(a),
+ "cons"=cons,
+ "concat"=do_concat
)