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
;; 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)) ) |
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
;; SICP 1.5 | |
;; Given: | |
;; | |
;; (define (p) (p)) | |
;; | |
;; (define (test x y) | |
;; (if (= x 0) | |
;; 0 | |
;; y)) |
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
;; 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) |
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
;; 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 |
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
class C | |
CC = Object.new | |
def self.new | |
CC | |
end | |
end |
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
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" |
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'ripper' | |
require 'sorcerer' | |
class EvalErr | |
def initialize(str) | |
@string = str | |
end |
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
class FL | |
def initialize(array) | |
@ary = array | |
end | |
def ==(array) | |
to_ary == array | |
end | |
def to_ary | |
@ary | |
end |
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
class FL | |
def initialize(array) | |
@ary = array | |
end | |
def ==(array) | |
to_ary == array | |
end | |
def to_ary | |
@ary | |
end |
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
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', |