-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
153 lines (152 loc) · 3.61 KB
/
README
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
-----------------------------------------
1) Built in operators:
+,-,*,/,%,==,!=,<=,>=,<,>,;
-----------------------------------------
2) Integers and floats in arithmetics:
1 or 2.33333 or 0.34 or .34
-----------------------------------------
3) Arbitrary nesting of parentheses:
(1+2*(5+((3+4)*3)-6/2)+7*2)\n => 61
-----------------------------------------
4) Comments:
# A comment until the end of the line
/* A longer comment that
spans multiple lines
*/
-----------------------------------------
5) Built in keywords:
TRUE,FALSE,NULL,IF,ELSE,END
-----------------------------------------
6) Built in functions:
HELP,ENV,SIZE,SPLIT,ROUND,MIN,MAX
SUM,MULT,AVG, PRINT, PRINT_LINE
TO_INT, TO_FLOAT, TO_ARRAY, AVG_SUM
MATCHING_IDS, VALUES_OF_TYPE
-----------------------------------------
7) Standard library functions:
foreach_in, inject, map, select
reject, in_groups_of, sum_of_type
avg_sum_of_type, avg_range_sum_of_type
total_range_sum_of_type, ratio
year_from_date, month_from_date,
hash_values, hash_value_sum,
avg_hash_value_sum, hash_range_values,
hash_range_value_sum,
avg_hash_range_value_sum
-----------------------------------------
8) Access the current environment:
ENV; (your output may differ)
=> { :a => 3, :foo => 5 }
Given the following environment:
{ :a => 1, :b => 2, :c => 3 }
ENV['a']
=> 1
ENV['a'..'b']
=> { :a => 1, :b => 2 }
-----------------------------------------
9) Numeric variables and literals
3;
=> 3
a = 3;
=> 3
a;
=> 3
-----------------------------------------
10) String variables and literals
"This is a string";
=> "This is a string";
'This is a string';
=> "This is a string";
s1 = "This is a string"; s1;
=> "This is a string"
s2 = 'This is a string'; s2;
=> "This is a string"
SIZE(s1);
=> 16
SIZE("foo");
=> 3
-----------------------------------------
11) Variables and closure applications
a = 3; foo = 5;
calc = fun(x,y) { (x + y) * a + foo };
calc(2,2);
=> 17
-----------------------------------------
12) Array variables and literals
arr = [1, [fun(){2}()], fun(x){x}(3)]
SIZE(arr);
=> 3
SIZE([1,2,3]);
=> 3
[1,2,3] + [4,[5,6]];
=> [1,2,3,4,[5,6]]
[1,2,3] - [[1],2,3];
=> [1]
-----------------------------------------
13) Hash variables and literals
h = { 1 => fun(){2}(), 'a' => 'foo' }
SIZE(h);
=> 2
h[1];
=> 'fun(){2}()'
h['a'];
=> 'foo'
SIZE({ 1 => 2});
=> 1
-----------------------------------------
14) Range variables and literals
range_including_upper = 1..5
=> [ 1, 2, 3, 4, 5 ]
SIZE(range_including_upper);
=> 5
range_excluding_upper = 1...5
=> [ 1, 2, 3, 4 ]
SIZE(range_excluding_upper);
=> 4
SIZE([1..5);
=> 5
-----------------------------------------
15) Conditional branching and recursion:
factorial = fun(x) {
if(x == 0)
1
else
x * factorial(x - 1)
end
}
factorial(5);
=> 120
-----------------------------------------
16) Conditional branching:
foo = fun(x) {
if(x == 0)
0
elsif(x == 1)
1
else
2
end
}
foo(0);
=> 0
foo(1);
=> 1
foo(2);
=> 2
-----------------------------------------
17) case expressions:
foo = fun(x) {
case x
when NULL then NULL
when 0 then 0
when 1 then 1
when 2 then 2
else
3
end
}
foo(1);
=> 1
foo(3);
=> 3
-----------------------------------------