This file contains 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
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); | |
} | |
} |
This file contains 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
#lang r5rs | |
;;;; | |
; From the paper: | |
; Relational Programming in miniKanren: | |
; Techniques, Applications, And Implementations | |
; William E. Byrd | |
;;;; | |
;; | |
;; Conventions: |
This file contains 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
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) |
This file contains 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
-- 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))) |