I propose that those of us who haven't yet read SICP resolve to beginning reading SICP right now. Let's use this thread for discussion, Q&A, and sharing our solutions to the exercises. Come, let us share in the joy, the pain, and the triumph. There will be Knights of the Lambda Calculus badges for all.
;;; 1.3
(define (f x y z)
(- (+ (square x)
(square y)
(square z))
(square (min x y z))))
;;; 1.4
; If b is greater than zero, return the sum of a and b, otherwise
; return the difference.
;;; 1.5
; If order is normal, y will never be evaluated and test will return zero,
; otherwise there will be an infinite loop before test is ever called.
;;; 1.6
; sqrt-iter will be evaulated every time new-if is called resulting in an
; infinite recursive loop of sqrt-iter.
(define (A x y)
(cond ((= y 0) 0)
((= x 0) (* 2 y))
((= y 1) 2)
(else (A (- x 1)
(A x (- y 1))))))
(A 1 10)
(A 0 (A 1 9))
(A 0 (A 0 (A 1 8)))
(A 0 (A 0 (A 0 (A 1 7))))
(A 0 (A 0 (A 0 (A 0 (A 1 6)))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 1 5))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 4)))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 3))))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 2)))))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 1))))))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 2)))))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 4))))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 8)))))))
(A 0 (A 0 (A 0 (A 0 (A 0 (A 0 16))))))
(A 0 (A 0 (A 0 (A 0 (A 0 32)))))
(A 0 (A 0 (A 0 (A 0 64))))
(A 0 (A 0 (A 0 128)))
(A 0 (A 0 256))
(A 0 516)
1024
(A 2 4)
(A 1 (A 2 3))
(A 1 (A 1 (A 2 2)))
(A 1 (A 1 (A 1 (A 2 1))))
(A 1 (A 1 (A 1 2)))
(A 1 (A 1 (A 0 (A 1 1))))
(A 1 (A 1 (A 0 2)))
(A 1 (A 1 4))
(A 1 (A 0 (A 1 3)))
(A 1 (A 0 (A 0 (A 1 2))))
(A 1 (A 0 (A 0 (A 0 (A 1 1)))))
(A 1 (A 0 (A 0 (A 0 2))))
(A 1 (A 0 (A 0 4)))
(A 1 (A 0 8))
(A 1 16) ; 2^16 = 65536
(A 3 3)
(A 2 (A 3 2))
(A 2 (A 2 (A 3 1)))
(A 2 (A 2 2))
(A 2 (A 1 (A 2 1)))
(A 2 (A 1 2))
(A 2 (A 0 (A 1 1)))
(A 2 (A 0 2))
(A 2 4) ; 65536
(define (f n) (A 0 n)) ; computes 2n
(define (g n) (A 1 n)) ; computes 2^n
(define (h n) (A 2 n)) ; computes 2^n
(define (k n) (* 5 n n)) ; computes 5n^2
Name:
Anonymous2012-02-25 16:36
New to Scheme. What's a decent interpreter that isn't bloated as fuck? MIT Scheme has insane error handling and won't let me run scripts from the command line. Bonus points for arrow key bindings.
A racket is an illegal business, usually run as part of organized crime. Engaging in a racket is called racketeering.
Name:
Anonymous2012-02-25 16:48
>>9 A racket is an illegal business
Nope. Government uses racket in the form of taxation and money printing (producing inflation), while it also uses armed forces to coerce population. Corrupt government official frequently want money to give green light for your business.
Name:
Anonymous2012-02-25 16:50
>>9 Racket
Not bloated >>8
Just install Guile and put this in your ~/.guile for history and tab completion. (use-modules (ice-9 readline))
(activate-readline)
(readline-disable 'history-file)
ive been using chicken but i plan to switch to guile
Name:
Anonymous2012-02-25 17:45
>>8
Chicken and Guile are pretty light, but they don't seem to offer much in the way of a REPL in themselves. You could try to use them from a common interface to such things, such as from Emacs or the like, but if you're going that route and don't know Emacs already, you'd be better off just biting the bullet and downloading Racket.
>>17 (PRC () (values -8
(error "Timezone for PRC not implemented -
Don't forget that 10000 students were murdered by the government
of the \"People's Republic of China\" in June 1989!"
) ) )
Clisp: [1]> (time (loop for i from 0 to 1000000 summing i))
Real time: 1.898606 sec.
Run time: 1.896119 sec.
Space: 9648 Bytes
500000500000
SBCL: * (time (loop for i from 0 to 1000000 summing i))
Evaluation took:
0.009 seconds of real time
0.008001 seconds of total run time (0.008001 user, 0.000000 system)
88.89% CPU
20,736,155 processor cycles
0 bytes consed