Skip to content

Instantly share code, notes, and snippets.

class Parent
class << self
def children
@children ||= []
end
def inherited(cls)
children << cls
end
end
end
module ConcernedParent
module ClassMethods
def children
@children ||= []
end
def inherited(cls)
children << cls
end
end
def self.included(cls)
(defn reject-multiples
"A function that rejects multiples of n."
[n]
(fn [x] (not (zero? (mod x n)))))
(defn primes
"An infinite sequence of prime numbers"
([] (primes (iterate inc 2)))
([seq]
(let [head (first seq)]
RUBY = File.join(
Config::CONFIG['bindir'],
Config::CONFIG['ruby_install_name'] + Config::CONFIG['EXEEXT']).
sub(/.*\s.*/m, '"\&"')
%w(some_method some_other_method).each do |method|
it "should call #{method}" do
obj.should_receive(:some_method).once
test_code_here
end
end
[Object|should_receive();new_instances();flexmock_get();flexmock_teardown();flexmock_verify()]
[Object]obj<->flexmock_proxy[PartialMockProxy|should_receive()]
[PartialMockProxy]->mock[Mock|should_receive()]
[Object]<-[note:These 5 methods are dynamically added to a partially mocked object]
[PartialMockProxy]<-[note:Proxies mediate between the mock and object]
[Mock]<-[note:Regular mock object. Knows nothing about proxies or real object.]
;; Exercise 1.1. Below is a sequence of expressions. What is the
;; result printed by the interpreter in response to each expression?
;; Assume that the sequence is to be evaluated in the order in which
;; it is presented.
;; 10
;; => 10
;; (+ 5 3 4)
;; => 12
;; SICP 1.4
;;
;; Exercise 1.4. Observe that our model of evaluation allows for
;; combinations whose operators are compound expressions. Use this
;; observation to describe the behavior of the following procedure:
(define (a-plus-abs-b a b)
((if (> b 0) + -) a b))
;; (a-plus-abs-b 2 3)
;; Exercise 1.8. Newton's method for cube roots is based on the fact
;; that if y is an approximation to the cube root of x, then a better
;; approximation is given by the value
;;
;; Use this formula to implement a cube-root procedure analogous to
;; the square-root procedure. (In section 1.3.4 we will see how to
;; implement Newton's method in general as an abstraction of these
;; square-root and cube-root procedures.)
;; ANSWER ------------------------------------------------------------
;; SICP Exercise 1.2:
;; Translate the following expression into prefix form
(/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 1 5)))))
(* 3 (- 6 2) (- 2 7)) )
;; => -71/300
;; or -0.236666666666667