Skip to content

Instantly share code, notes, and snippets.

View kaz-yos's full-sized avatar
💭
I may be slow to respond.

Kazuki Yoshida kaz-yos

💭
I may be slow to respond.
View GitHub Profile
@kaz-yos
kaz-yos / foldx.lisp
Last active August 29, 2015 14:19 — forked from ha2ne2/foldx.lisp
(defun foldr (f lst)
(if (null (cdr lst)) (car lst)
(funcall f (car lst) (foldr f (cdr lst)))))
(defun foldl (f lst)
(if (null (cdr lst)) (car lst)
(funcall f (foldl f (butlast lst)) (car (last lst)))))
(defun foldr-tail (f a lst)
(if (null lst) a
@kaz-yos
kaz-yos / lispr.R
Last active August 29, 2015 14:12 — forked from igjit/lispr.R
## Scheme Interpreter in R
## (more R-ish implementation of "lisp.R")
addGlobals <- function(env) {
procs <- list("+" = sum,
"*" = prod,
"-" = function(...) Reduce(`-`, list(...)),
"/" = function(...) Reduce(`/`, list(...)),
"=" = `==`,
"eq?" = `==`,
#' R implementation of `cond` from Lisp
#' allows for arbitrary numbers of conditionals without ugly nested if statements
#' conditionals are entered as pairs of expressions (clauses),
#' first the expression to be evaluated and second the return value if the expression is true
#' @param ... an even number of expressions as pairs (see example)
#' @param true the `else` expression (Taken from the Lisp (T resultN) see http://www.cis.upenn.edu/~matuszek/LispText/lisp-cond.html)
#' @return The paired value of the first true conditional expression or the value of true
#' @examples
#' x <- runif(1)
#' cond(x < 0.2, "lower tail",