Skip to content

Instantly share code, notes, and snippets.

@trobertson
trobertson / fun.js
Created December 13, 2012 20:30 — forked from zachallaun/fun.js
var data = [0,1,2,3,4,5,6,7,8,9];
function test() {
var g = window;
g.result = [];
for(var i = 0; i < data.length; i++) {
if(data[i] % 2 === 0) {
g.result.push(data[i]*2);
}
}
@trobertson
trobertson / temp.ss
Created December 11, 2012 19:53
bsdfk
#lang r5rs
;;;;
; From the paper:
; Relational Programming in miniKanren:
; Techniques, Applications, And Implementations
; William E. Byrd
;;;;
;;
;; Conventions:
@trobertson
trobertson / zipper.hs
Created December 5, 2012 20:14
zipper type
module Data.Zipper where
data ZipperList a = ZL {
prev :: [a]
, next :: [a]
}
-- it's an efficient list traversal, so we should be able to map over it
instance Functor ZipperList where
fmap foo (ZL p n) = ZL (fmap foo p) (fmap foo n)
-- adds up how many zeros are in the elements of a list
cz :: Show a => [a] -> Int
cz = sum . map length . map (filter (=='0')) . map show
-- the (.) means function composition, and lets you exclude the
-- variable being operated on. so:
-- f . g == f (g (x))
cz' :: Show a => [a] -> Int
cz' s = sum (map length (map (filter (=='0')) (map show s)))