Skip to content

Commit 91ff311

Browse files
committed
Moved to built-in classes and methods
1 parent 40715ca commit 91ff311

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+2093
-4646
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ All documentation can be found in the [wiki](https://github.com/tomdodd4598/Dodd
1616
Planned Features
1717
----------------
1818

19-
- Combine TypeElement into ClassElement
20-
- Various keywords replaced with static or member functions.
19+
- All planned features currently implemented!
2120

2221
Permissions
2322
-----------

run/classes.dssl

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -81,66 +81,6 @@ item .printRecursive
8181

8282
'\n' print
8383

84-
# -------------- #
85-
# COMPLEX NUMBER #
86-
# -------------- #
87-
88-
/Complex {
89-
/init {
90-
/this exch def
91-
/this .im exch def
92-
/this .re exch def
93-
this
94-
} magic
95-
96-
/i 0.0 1.0 Complex new def
97-
98-
/binaryDefs "dup .re /xre exch def .im /xim exch def dup .re /yre exch def .im /yim exch def" def
99-
100-
/add {
101-
Complex .binaryDefs interpret
102-
xre yre + xim yim + Complex new
103-
} magic
104-
105-
/sub {
106-
Complex .binaryDefs interpret
107-
xre yre - xim yim - Complex new
108-
} magic
109-
110-
/mul {
111-
Complex .binaryDefs interpret
112-
xre yre * xim yim * - xre yim * xim yre * + Complex new
113-
} magic
114-
115-
/div {
116-
Complex .binaryDefs interpret
117-
/ysq yre yre * yim yim * + def
118-
xre yre * xim yim * + ysq / xim yre * xre yim * - ysq / Complex new
119-
} magic
120-
121-
/toString {
122-
/this exch def
123-
this .re string
124-
this .im 0.0 >= { '+' ~ } if
125-
this .im string ~ 'i' ~
126-
} macro
127-
} class
128-
129-
/a 2.3 3.4 Complex new def
130-
/b 6.2 -1.9 Complex new def
131-
132-
a Complex .toString println
133-
b .toString println
134-
135-
'\n' print
136-
137-
"a+b = " print a b + .toString println
138-
"a-b = " print a b - .toString println
139-
"a*b = " print a b * .toString println
140-
"a/b = " print a b / .toString println
141-
142-
'\n' print
143-
14484
# ------------------- #
14585
# DIAMOND INHERITANCE #
14686
# ------------------- #

run/fibonacci.dssl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030
} if
3131
} macro
3232

33-
[ 1 11 ] range {
33+
[ 1 11 ] range new {
3434
fib println
3535
} foreach

run/math.dssl

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# --------------- #
2+
# COMPLEX NUMBERS #
3+
# --------------- #
4+
5+
$math include
6+
7+
/Complex {
8+
/init {
9+
/this exch def
10+
/this .im exch def
11+
/this .re exch def
12+
this
13+
} magic
14+
15+
/eq {
16+
dup .re /yre exch def .im /yim exch def
17+
dup .re /xre exch def .im /xim exch def
18+
xre yre == xim yim == &
19+
} magic
20+
21+
/ne {
22+
dup .re /yre exch def .im /yim exch def
23+
dup .re /xre exch def .im /xim exch def
24+
xre yre != xim yim != |
25+
} magic
26+
27+
/add {
28+
dup .re /yre exch def .im /yim exch def
29+
dup .re /xre exch def .im /xim exch def
30+
xre yre + xim yim + Complex new
31+
} magic
32+
33+
/sub {
34+
dup .re /yre exch def .im /yim exch def
35+
dup .re /xre exch def .im /xim exch def
36+
xre yre - xim yim - Complex new
37+
} magic
38+
39+
/mul {
40+
dup .re /yre exch def .im /yim exch def
41+
dup .re /xre exch def .im /xim exch def
42+
xre yre * xim yim * - xre yim * xim yre * + Complex new
43+
} magic
44+
45+
/div {
46+
dup .re /yre exch def .im /yim exch def
47+
dup .re /xre exch def .im /xim exch def
48+
/ysq yre yre * yim yim * + def
49+
xre yre * xim yim * + ysq / xim yre * xre yim * - ysq / Complex new
50+
} magic
51+
52+
/pow {
53+
dup .re /yre exch def .im /yim exch def
54+
dup .abs log /xlnr exch def .arg /xtheta exch def
55+
xlnr yre * xtheta yim * - exp xtheta yre * xlnr yim * + Complex .fromPolar
56+
} magic
57+
58+
/abs {
59+
dup .re /re exch def .im /im exch def
60+
re re * im im * + sqrt
61+
} macro
62+
63+
/arg {
64+
dup .im exch .re atan2
65+
} macro
66+
67+
/fromPolar {
68+
/theta exch def
69+
/r exch def
70+
r theta cos * r theta sin * Complex new
71+
} macro
72+
73+
/toString {
74+
/this exch def
75+
this .re string cast
76+
this .im 0.0 >= { '+' ~ } if
77+
this .im string cast ~ 'i' ~
78+
} macro
79+
} class
80+
81+
/a 2.7 3.4 Complex new def
82+
/b 4.2 -1.9 Complex new def
83+
84+
"a = " a Complex .toString ~ println
85+
"b = " b Complex .toString ~ println
86+
87+
'\n' print
88+
89+
"abs(a) = " a .abs ~ println
90+
"arg(b) = " b .arg ~ println
91+
92+
'\n' print
93+
94+
"a+b = " a b + .toString ~ println
95+
"a-b = " a b - .toString ~ println
96+
"a*b = " a b * .toString ~ println
97+
"a/b = " a b / .toString ~ println
98+
"a**b = " a b ** .toString ~ println

0 commit comments

Comments
 (0)