generated from calcit-lang/calcit-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compact.cirru
77 lines (76 loc) · 2.35 KB
/
compact.cirru
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{} (:package |arithmetic)
:configs $ {} (:init-fn |arithmetic.test/main!) (:reload-fn |arithmetic.test/reload!) (:version |0.0.1)
:modules $ [] |calcit-test/
:entries $ {}
:files $ {}
|arithmetic.test $ {}
:ns $ quote
ns arithmetic.test $ :require
calcit-test.core :refer $ deftest testing is *quit-on-failure?
arithmetic.complex :as 2d
:defs $ {}
|main! $ quote
defn main! () $ run-tests
|reload! $ quote
defn reload! () (run-tests) (println "\"reloaded.")
|run-tests $ quote
defn run-tests () (reset! *quit-on-failure? true) (test-basic)
|test-basic $ quote
deftest test-basic
testing |add $ is
= ([] 3 5)
2d/&+ ([] 1 2) ([] 2 3)
testing |minus $ is
= ([] -1 -1)
2d/&- ([] 1 2) ([] 2 3)
|arithmetic.complex $ {}
:ns $ quote (ns phlox.complex)
:defs $ {}
|&* $ quote
defn &* (v1 v2)
let-sugar
[] a b
, v1
([] x y) v2
[]
- (* a x) (* b y)
+ (* a y) (* b x)
|&+ $ quote
defn &+ (p1 p2)
let-sugar
[] a b
, p1
([] x y) p2
[] (+ a x) (+ b y)
|&- $ quote
defn &- (v1 v2)
let-sugar
[] a b
, v1
([] x y) v2
[] (- a x) (- b y)
|&/ $ quote
defn rebase (value base) "\"complex number division, renamed since naming collision" $ let-sugar
[] x y
, value
([] a b) base
inverted $ / 1
+ (* a a) (* b b)
[]
* inverted $ + (* x a) (* y b)
* inverted $ - (* y a) (* x b)
|conjugate $ quote
defn conjugate (pair) (update pair 1 negate)
|divide-by $ quote
defn divide-by (point x)
[]
/ (first point) x
/ (last point) x
|polar-point $ quote
defn polar-point (angle r)
[]
* r $ js/Math.cos angle
* r $ js/Math.sin angle
|scale $ quote
defn scale (pair v)
map pair $ fn (x) (* v x)