-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhierarchy.fn
100 lines (79 loc) · 2.21 KB
/
hierarchy.fn
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Built-in object zoo.
# This is the ideal case...
# The Global object is created at the start of any execution
# and is the parent object for all objects.
Global = () {
# Alias of Bool.not().
not = (obj) { obj.not() }
}
# In Fn, any custom value is automatically an Object.
Object = (obj) {
# Returns a reference to itself.
this = <builtin>
# Returns true if two objects have the same value.
eq = (other) { <builtin> }
# Returns a string representation of the object.
asString = () { <builtin> }
# This function is run when the object is referenced like:
# obj(1)
# By default, it returns the property given by the argument.
call = (propertyName) { <builtin> }
# Returns the number of arguments the object will take when call()ed.
arity = () { <builtin> }
# Iterates over the properties of the object,
# calling the given function for each one.
each = (f) { <builtin> }
}
# A Bool represents either a true or false value.
Bool = (value) {
# Include Object and override.
include Object {
eq = (other) { <builtin> }
asString = () { <builtin> }
}
# Returns true if both this and the other are true.
and = (other) { <builtin> }
# Returns true if either this or the other are true.
or = (other) { <builtin> }
# Returns the opposite of the value:
# (true).flip() = false
# (false).flip() = true
not = () { <builtin> }
}
# A Number represents a numeric value.
Number = (value) {
include Object {
eq = (other) { <builtin> }
asString = () { <builtin> }
})
# Arithmetic operations.
+ = (other) { <builtin> }
- = (other) { <builtin> }
* = (other) { <builtin> }
/ = (other) { <builtin> }
# Comparison operations.
lessThan = (other) { <builtin> }
moreThan = (other) { <builtin> }
}
# A String represents a collection of characters.
String = (value) {
include Object {
eq = (other) { <builtin> }
asString = () { <builtin> }
}
}
# A Def is a function definition:
# a set of instructions that can be called.
Def = (value) {
include Object {
asString = () { <builtin> }
}
}
# A List is a collection of objects.
List = (...values) {
include Object {
eq = (other) { <builtin> }
asString = () { <builtin> }
each = (f) { <builtin> }
}
}