Created
May 6, 2010 13:54
-
-
Save Mozk0/392146 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rexp.to.sexp <- function(exp){ | |
exp <- substitute(exp) | |
if(is.call(exp)) { | |
s <- "(" | |
i <- 0 | |
while (i < length(exp)) { | |
i <- i + 1 | |
separator <- if( i == 1 ) "" else " " | |
s <- paste(s, | |
eval(substitute(rexp.to.sexp(e), list(e = exp[[i]]))), | |
sep = separator) | |
} | |
paste(s, ")", sep = "") | |
} else if (is.list(exp)) { | |
eval(substitute(rexp.to.sexp(e), list(e = as.call(Map(as.name, names(exp)))))) | |
} else if (is.character(exp)) { | |
paste("\"", as.character(exp), "\"", sep="") | |
} else { | |
as.character(exp) | |
} | |
} | |
rexp.to.scheme.exp <- function(exp){ | |
exp <- substitute(exp) | |
if (is.call(exp)) { | |
if (exp[[1]] == quote(`function`)) { | |
exp <- exp[-length(exp)] | |
} | |
s <- "(" | |
i <- 0 | |
while (i < length(exp)) { | |
i <- i + 1 | |
separator <- if( i == 1 ) "" else " " | |
s <- paste(s, | |
eval(substitute(rexp.to.scheme.exp(e), list(e = exp[[i]]))), | |
sep = separator) | |
} | |
paste(s, ")", sep = "") | |
} else if (is.list(exp)) { | |
eval(substitute(rexp.to.sexp(e), list(e = as.call(Map(as.name, names(exp)))))) | |
} else if (is.character(exp)) { | |
paste("\"", as.character(exp), "\"", sep="") | |
} else if(exp == quote(`<-`)) { | |
"define" | |
} else if (exp == quote(`{`)) { | |
"begin" | |
} else if (exp == quote(`(`)) { | |
"begin" | |
} else if (exp == quote(`function`)) { | |
"lambda" | |
} else if (exp == quote(`[`)) { | |
"aref" | |
} else { | |
as.character(exp) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment