Skip to content

Instantly share code, notes, and snippets.

@steveshogren
steveshogren / gist:1548573
Created January 1, 2012 22:52
ConcreteMock
<?php
class Velocity {
public function __construct (PayoffCalc $PayoffCalc)
{
$this->_PayoffCalc = $PayoffCalc;
}
public function toFloat()
{
$paymentPerDay = $this->_PayoffCalc->getPaymentPerDay();
def doCalc ()
return 1 + 2
end
def doAwesome (x)
return doCalc() + x
end
#before substitution...
def test ()
return doAwesome(3)
;; trace-forms "Trace all the forms in the given body. Returns any
;; underlying uncaught exceptions that may make the forms fail."
(trace-forms
(let [a (+ 1 1)
b (* 2 2)
c (* a b (/ 4 0))]
c))
;; => ArithmeticException Divide by zero
;; Form failed: (/ 4 0)
;; Form failed: (* a b (/ 4 0))
;; example up from clouredocs.org:
;; http://clojuredocs.org/clojure_contrib/clojure.contrib.trace/deftrace
(deftrace fib [n]
(if (or (= n 0) (= n 1))
1
(+ (fib (- n 1)) (fib (- n 2)))))
(fib 4)
;; => 5
;; 1> TRACE t2742: (fib 4)
if workday(today()) do
x = 1 + 1
else
x = doOtherHugeCalc()
end
def ifworkday(first, second)
if workday(today()) do
return first
else
return second
end
end
x = ifworkday(1 + 1, doOtherHugeCalc())
#when the values are “shown”
#if it is a macro...
defmacro ifworkday(first, second)
if workday(today()) do
return first
else
return second
end
end
ifworkday(1+1, doOtherHugeCalc())
‘(a b c d)
;;=> (a b c d)
(= ‘a ‘a)
;;=> true
(= a a)
;; => java.lang.Exception: Unable to resolve symbol: a in this context