aboutsummaryrefslogtreecommitdiff
path: root/r/printer.r
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-11-02 21:32:33 -0600
committerJoel Martin <github@martintribe.org>2015-01-09 16:16:43 -0600
commit01feedfe22a381c6b6ca79bdf0db798aa08c4104 (patch)
treeacee75da927f3d4234f7433801584ca750502a9f /r/printer.r
parent4d1456b98f34bfa74aea912469aa246b56273d76 (diff)
downloadmal-01feedfe22a381c6b6ca79bdf0db798aa08c4104.tar.gz
mal-01feedfe22a381c6b6ca79bdf0db798aa08c4104.zip
R: add step4_if_fn_do and step5_tco.
Switch nil from NULL to special class.
Diffstat (limited to 'r/printer.r')
-rw-r--r--r/printer.r23
1 files changed, 18 insertions, 5 deletions
diff --git a/r/printer.r b/r/printer.r
index 1695439..0a10d37 100644
--- a/r/printer.r
+++ b/r/printer.r
@@ -2,28 +2,41 @@
if(!exists("..types..")) source("types.r")
+.pr_list <- function(..., print_readably=TRUE, join="") {
+ concatl(lapply(list(...),
+ function(e) .pr_str(e, print_readably)), sep=join)
+}
+
.pr_str <- function(exp, print_readably=TRUE) {
- #cat("-", class(exp), as.character(exp), "\n")
+ pr <- print_readably
switch(class(exp),
"List"={
- data <- paste(lapply(exp, function(e) .pr_str(e)),
+ data <- paste(lapply(exp, function(e) .pr_str(e, pr)),
sep="", collapse=" ")
paste("(", data, ")", sep="", collapse="")
},
"Vector"={
- data <- paste(lapply(exp, function(e) .pr_str(e)),
+ data <- paste(lapply(exp, function(e) .pr_str(e, pr)),
sep=" ", collapse=" ")
paste("[", data, "]", sep="", collapse="")
},
"character"={
if (print_readably) {
- paste("\"", exp, "\"", sep="", collapse="" )
+ paste("\"",
+ gsub("\\n", "\\\\n",
+ gsub("\\\"", "\\\\\"",
+ gsub("\\\\", "\\\\\\\\", exp))),
+ "\"", sep="", collapse="")
} else {
exp
}
},
- "NULL"={ "nil" },
+ "nil"={ "nil" },
"logical"={ tolower(exp) },
+ "MalFunc"={
+ paste("(fn* ", .pr_str(exp$params,TRUE),
+ " ", .pr_str(exp$ast, FALSE), ")", sep="")
+ },
"function"={ "<#function>" },
{ toString(exp) })
}