-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmagic-cmp.edh
64 lines (43 loc) · 1.1 KB
/
magic-cmp.edh
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
{
class CreditRating {
market'grade = 0 # static default value
method __init__( sym as this.sym, ***_ ) this.score = case this.sym of {
'AAA' -> 100
'AA' -> 80
'A' -> 70
'BBB' -> 60
'BB' -> 50
'B' -> 40
'CCC' -> 30
'CC' -> 20
'C' -> 10
'D' -> 0
'NR' -> NA
assert( false, 'invalid rating symbol: ' ++ this.sym )
None
}
method __repr__() this.sym
method __compare__( other ) case other of {
{ { CreditRating: r } } -> case true of {
that.market'grade > r.market'grade -> GT
that.market'grade < r.market'grade -> LT
that.score > r.score -> GT
that.score < r.score -> LT
_ -> EQ
}
_ -> NA
}
}
class RatedOnEarth { extends CreditRating
market'grade = 100 # static default value
}
class FictionalRating { extends CreditRating
market'grade = -100 # static default value
}
}
BBB'on'earth = RatedOnEarth( 'BBB' )
phantom'AAA = FictionalRating( 'AAA' )
{
console.print$ 'Should you believe that? - '
++ phantom'AAA > BBB'on'earth
}