From c30efef469e22c8ba345a72c058c28362e57b746 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Mon, 3 Nov 2014 20:02:09 -0600 Subject: R: add step6_file and step7_quote Change symbols to be special class. --- r/core.r | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'r/core.r') 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"=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 ) -- cgit v1.2.3