Skip to content

Instantly share code, notes, and snippets.

View mohanrajendran's full-sized avatar

Mohan Rajendran mohanrajendran

View GitHub Profile
@mohanrajendran
mohanrajendran / Exercise1-5.md
Last active August 29, 2015 14:03
SICP Exercise 1.5
(define (p) (p))

(define (test x y)
  (if (= x 0)
      0
      y))

(test 0 (p))
@mohanrajendran
mohanrajendran / Exercise1-4.md
Last active August 29, 2015 14:03
SICP Exercise 1.4
(define (a-plus-abs-b a b)
  ((if (> b 0) + -) a b))

When the if function is evaluated, based on the condition, the operator + or - is applied on the operands a and b. If b > 0, + operator is used, evaluating to a+b. Otherwise, - operator is issued which yields a-b. Ultimately, we evaluate a+|b|.

@mohanrajendran
mohanrajendran / Exercise1-3.scm
Created July 6, 2014 23:27
SICP Exercise 1.3
(define (sq x) (* x x))
; sq
(define (sumsq x y) (+ (sq x) (sq y)))
; sumsq
(define (largest2sq a b c)
(cond ((and (<= a b) (<= a c)) (sumsq b c))
((and (<= b a) (<= b c)) (sumsq a c))
(else (sumsq a b))))
@mohanrajendran
mohanrajendran / Exercise1-2.scm
Created July 6, 2014 23:26
SICP Exercise 1.2
(/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5)))))
(* 3 (- 6 2) (- 2 7)))
; -37/150
@mohanrajendran
mohanrajendran / Exercise1-1.scm
Created July 6, 2014 23:26
SICP Exercise 1.1
10
; 10
(+ 5 3 4)
; 12
(- 9 1)
; 8
(/ 6 2)