-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsimple-class.edh
58 lines (40 loc) · 1.42 KB
/
simple-class.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
{
class C {
# __init__() is called on object construction, used to receive
# construction arguments
method __init__ ( a as this._a ) pass
# property can be defined using getter and optional setter method
property$ method a () this._a
setter$ method a ( a as this._a ) pass
# an old-school setter method works of course
method setB( b as this.b ) pass
# a class level (static) attribute
#
# - is available and can be changed from/via the class object via
# dot-notation
#
# - serves as default value for instance attribute when accessed via
# dot-notation
#
# - is available directly (no dot-notation) to all methods defined within
# the class scope, as the class scope is lexically the outer scope of
# such a method procedure; but note assigning in a method procedure
# will change it's local scope's attribute, to change a class attribute,
# assignment via dot-notation against the class object is necessary
#
b = 5
method f ( n ) n * this.a / this.b
method g ( n ) { v = ( n+3 ) / this.a; return v * b }
}
o = C( 17 )
; # this semicolon is necessary,
# or the following apk will parse as a call against the assignment result,
# which is the newly constructed C object.
( o.f( 7 ), o.g( 7 ) )
}
( o.a, o.b )
o.a = 11; o.setB( 23 )
( o.a, o.b )
( o.f( 7 ), o.g( 7 ) )
C.b = 3; o.b = 13
( o.f( 7 ), o.g( 7 ) )