Last active
September 27, 2016 20:33
-
-
Save QuantumFractal/c0a6606b303c8ced3f3c1c2fc5263b9d to your computer and use it in GitHub Desktop.
342 Sum / Map Example
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
(define sum | |
(lambda (lst) | |
(if (null? lst) | |
0 | |
(+ (car lst) (sum (cdr lst))) | |
) | |
) | |
) | |
(define map | |
(lambda (f lst) | |
(if (null? lst) | |
(list) | |
(cons (f (car lst)) (map f (cdr lst))) | |
) | |
) | |
) | |
(define a_list (list 1 2 3 4)) | |
(define addone (lambda (x) (+ x 1))) | |
(sum (map addone a_list)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment