solution to 2.33 in scheme
authorRamakrishnan Muthukrishnan <vu3rdd@gmail.com>
Sat, 16 Oct 2010 19:40:54 +0000 (01:10 +0530)
committerRamakrishnan Muthukrishnan <vu3rdd@gmail.com>
Sat, 16 Oct 2010 19:40:54 +0000 (01:10 +0530)
src/sicp/ex2_33.rkt [new file with mode: 0644]

diff --git a/src/sicp/ex2_33.rkt b/src/sicp/ex2_33.rkt
new file mode 100644 (file)
index 0000000..312ea07
--- /dev/null
@@ -0,0 +1,24 @@
+#lang racket
+
+(require "utils.rkt")
+
+(define (map f coll)
+  (accumulate (lambda (x y) (cons (f x) y))
+              '()
+              coll))
+
+(map square '(1 2 3 4 5))
+
+(define (append seq1 seq2)
+  (accumulate cons
+              seq2
+              seq1))
+
+(append '(1 2 3) '(4 5 6))
+
+(define (length seq)
+  (accumulate (lambda (x y) (+ 1 y))
+              0
+              seq))
+
+(length '(1 2 3 4 5))
\ No newline at end of file