Skip to content

Instantly share code, notes, and snippets.

;; SICP 1.3
;; Exercise 1.3. Define a procedure that takes three numbers as
;; arguments and returns the sum of the squares of the two larger
;; numbers.
(define (square x) (* x x))
(define (sum-of-squares a b)
(+ (square a) (square b)) )
;; SICP 1.5
;; Given:
;;
;; (define (p) (p))
;;
;; (define (test x y)
;; (if (= x 0)
;; 0
;; y))
;; SICP 1.5
;; Exercise 1.5. Ben Bitdiddle has invented a test to determine
;; whether the interpreter he is faced with is using applicative-order
;; evaluation or normal-order evaluation. He defines the following two
;; procedures:
;; (define (p) (p))
;;
;; (define (test x y)
;; SICP 1.7
;; Exercise 1.7. The good-enough? test used in computing square roots
;; will not be very effective for finding the square roots of very
;; small numbers. Also, in real computers, arithmetic operations are
;; almost always performed with limited precision. This makes our test
;; inadequate for very large numbers. Explain these statements, with
;; examples showing how the test fails for small and large numbers. An
;; alternative strategy for implementing good-enough? is to watch how
;; guess changes from one iteration to the next and to stop when the
class C
CC = Object.new
def self.new
CC
end
end
def f(should_fail=false)
puts "BODY 1"
fail if should_fail
puts "BODY 2"
rescue StandardError => ex
puts "RESCUE"
else
puts "ELSE"
ensure
puts "ENSURE"
#!/usr/bin/env ruby
require 'rubygems'
require 'ripper'
require 'sorcerer'
class EvalErr
def initialize(str)
@string = str
end
class FL
def initialize(array)
@ary = array
end
def ==(array)
to_ary == array
end
def to_ary
@ary
end
class FL
def initialize(array)
@ary = array
end
def ==(array)
to_ary == array
end
def to_ary
@ary
end
begin
require 'rcov/rcovtask'
Rcov::RcovTask.new do |t|
t.libs << "test"
dot_rakes =
t.rcov_opts = [
'-xRakefile', '-xrakefile', '-xpublish.rf',
'-xlib/rake/contrib', '-x/Library',
'--text-report',