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, '"\&"')
; Church Numerals in Clojure
;
; Church numerals use anonymous functions to represent numbers.
;
; ((zero f) x) -- returns x
; ((one f) x) -- return (f x)
; ((two f) x) -- return (f (f x))
; ...
(def zero (fn [f] (fn [x] x)))
%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 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
;; 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)) )