-
Notifications
You must be signed in to change notification settings - Fork 0
/
PRIMITIVE_FUNCTIONS
159 lines (134 loc) · 5.23 KB
/
PRIMITIVE_FUNCTIONS
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
*:
* Basic multiplication function.
* Input - A sequence of numbers, integer or floating point.
* Output - The product of the input numbers, floating point if any of the
* inputs were floating point.
+:
* Basic addition function.
* Input - A sequence of numbers, integer or floating point.
* Output - The sum of the input numbers, floating point if any of the input
* numbers was floating point, integer otherwise.
-:
* Basic subtraction function.
* Input - A sequence of numbers, integer or floating point.
* Output - The difference of each of the numbers, starting with the first
* value and subtracting each successive value in order. Result is floating
* point if any of the input numbers are floating point.
/:
* Basic division function.
* Input - A sequence of numbers, integer or floating point.
* Output - The quotient of each of the numbers, starting with the first
* value and subtracting each successive value in order. Result is a floating
* point number.
1+:
* Incrementor function.
* Input - An integer or floating point number.
* Output - The input + 1.
1-:
* Decrementor function.
* Input - An integer or floating point number.
* Output - The input - 1.
append:
* Appends an item to the end of a sequence.
* Input - A sequence of length 2. The second element must be a list.
* Output - The first element of the input appended onto the end of the second.
const:
* Constant function.
* Specializers - const(n)
* Input - Any value other than bottom.
* Output - The value n.
eq:
* Comparison function.
* Input - A sequence of two or more values.
* Output - True if all values in the sequence are equivalent, False if they are
* not, or bottom for invalid input.
float:
* Floating point conversion function.
* Input - Any value other than bottom.
* Output - A conversion of the input value to a floating point number.
* Integers are simply cast to floating point, floating point numbers are
* passed through verbatim. True becomes 1.0, False becomes 0.0. Chars are
* converted to their ASCII values and then cast to floating point. Strings
* are converted with the C atof funciton. Sequences simply return the
* sequence length.
gt:
* Greater-than comparator.
* Input - A sequence consisting either of all numbers, all characters, or all
* strings.
* Output - True if each successive element is ordered after the next, False
* otherwise.
gte:
* Greater-than-or-equal-to comparator.
* Input - A sequence consisting either of all numbers, all characters, or all
* strings.
* Output - True if each successive element is ordered after or equal to the
* next, False otherwise.
head:
* Returns the first element of a sequence.
* Input - A sequence.
* Output - The first item in that sequence, or <> if the sequence is empty.
id:
* Identity function.
* Input - Any value.
* Output - The same value as the input.
int:
* Integer conversion function.
* Input - Any value other than bottom.
* Output - A conversion of the input value to an integer. Floats are
* truncated, integers are passed through verbatim. True becomes 1, False
* becomes 0. Chars are converted to their ASCII values. Strings are
* converted with the C atoi function. Sequences simply return the sequence
* length.
length:
* Returns the length of a sequence.
* Input - A sequence.
* Output - The length of the sequence as an integer.
lt:
* Less-than comparator.
* Input - A sequence consisting either of all numbers, all characters, or
* all strings.
* Output - True if each successive element is ordered before the next, False
* otherwise.
lte:
* Less-than-or-equal-to comparator.
* Input - A Sequence consisting either of all numbers, all characters, or all
* strings.
* Output - True if each successive element is ordered before or equal to the
* next, False otherwise.
mod:
* Modulus operation.
* Input - A sequence of two or more integers.
* Output - The result of applying the modulus operator (remainder of division)
* between the first and second value, then between that result and the third
* value, and so on.
prepend:
* Prepends an item to the beginning of a sequence.
* Input - A sequence of length 2. The second element must be a list.
* Output - The first element of the input prepended to the beginning of the
* second.
print:
* Prints output to the screen.
* Input - A string value.
* Output - The same string that was passed in as input, or bottom if a
* non-string is passed in. In additition to passing its input through
* unchanged, the print function prints its string input out to the screen.
println:
* Prints output to a line on the screen.
* Input - A string value.
* Output - The same string that was passed in as input, or bottom if a
* non-string is passed in. In addition to passing its input through
* unchanged, the println function prints its string input to the screen with an
* additional newline at the end.
readln:
* Reads a line of input from the terminal.
* Input - Any non-bottom value.
* Output - A string containing a line read from the user.
str:
* String conversion function.
* Input - Any value other than bottom.
* Output - A conversion of the input value to a string.
tail:
* Returns the portion of a sequence after the head.
* Input - A sequence
* Output - A sequence containing every element in the input sequence except
* for the first, or <> if the sequence is empty.