-
Notifications
You must be signed in to change notification settings - Fork 3
/
help.cc
1353 lines (1337 loc) · 41.1 KB
/
help.cc
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <string>
static const char* _help[][2] = {
{ "overview",
"\nThere are four basic atomic types:\n"
"\n"
"- Int, a signed integer. (Equivalent to a 'long' in C.)\n"
"- UInt, an unsigned integer. (Equivalent to an 'unsigned long' in C.)\n"
"- Real, a floating-point number. (Equivalent to a 'double' in C.)\n"
"- String, a string, stored as a byte array.\n"
"\n"
"There are also four structured types:\n"
"\n"
"- Tuple, a sequence of several values of (possibly) different types.\n"
" The number of values and their types cannot change at runtime.\n"
"\n"
"- Array, an array of values. Elements can be added and removed at\n"
" runtime, but the type of all of the values is the same and cannot\n"
" change.\n"
"\n"
"- Map, a hash map (associative array) from values to values. Like with\n"
" the array, elements can be added and removed, but the type of keys\n"
" and values cannot change.\n"
"\n"
"- Sequence, a.k.a. 'lazy list' or 'generator'. A sequence doesn't\n"
" store any values, but will generate a new element in the sequence\n"
" each time is asked to. As with arrays, all generated elements are\n"
" of the same type.\n"
"\n"
"When outputing, each element of an array, map or sequence is printed\n"
"on its own line, even when nested inside some other structure. The\n"
"elements of a tuple are printed separated by a tab character, '\\t'.\n"
"\n"
"Maps, by default, store values in an unspecified order. Use the '-s'\n"
"command-line parameter to force a strict ordering on map keys.\n"
"\n"
"The default number type in 'tab' is the unsigned integer. A plain\n"
"sequence of digits will be interpreted as a UInt.\n"
"\n"
"'tab' has no loops or conditional 'if' statements; the input\n"
"expression is evaluated, and the resulting value is printed on\n"
"standard output.\n"
"\n"
"Instead of loops you'd use sequences and comprehensions.\n"
"\n"
"The input is a file stream, usually the standard input. A file stream\n"
"in 'tab' is represented as a sequence of strings, each string being a\n"
"line from the file.\n"
},
{ "syntax",
"\nLiteral values:\n"
" UInt: 1234 or 1234u or 0x4D2\n"
" Int: -1234 or 1234i or 1234s or 1234l\n"
" Real: +10.50 or 1. or 4.4e-10\n"
" String: 'chars' or \"chars\" or `${expr}`\n"
" supported escape sequences: \\t \\n \\r \\e \\\\\n"
" Tuple: a, b, c or a; b; c\n"
" Sequence: [ expr ] or [ expr : source ] also [ try ... ]\n"
" Array: [. expr .] or [. expr : source .] also [. try ... .]\n"
" Map: { key } or { key -> val } or { key -> val : source } also { try ... }\n"
" (Thrown exceptions will be ignored when there's an optional 'try'.)\n"
"\n"
"Function calls:\n"
" f(x) or f.x or $x\n"
"Defining variables:\n"
" x = expr\n"
"Defining functions:\n"
" def f expr or def f (exprs) or def [ a, b expr, ... ]\n"
"\n"
"Operators, in order of precedence:\n"
" a~b a[b]\n"
" :a ?a\n"
" !a\n"
" a**b\n"
" a*b a/b a%b\n"
" a+b a-b\n"
" a&b a|b a^b\n"
" a==b a!=b a<b a>b a<=b a>=b\n"
" a&&b a||b\n"
" a .. b\n"
"\n"
"Parentheses can be used for grouping. Use ',' or ';' for separating statements.\n"
"'a~b' is syntactic sugar for 'a[b]' is syntactic sugar for 'index(a,b)'\n"
"':a' is syntactic sugar for 'flatten(a)'.\n"
"'?a' is syntactic sugar for 'filter(a)'.\n"
"'a .. b' is syntactic sugar for '@=a, b'.\n"
"'[/ a]' is syntactic sugar for '[try if(a, @)]'.\n"
"\n"
"'@' is the variable name denoting input to a function or left side of\n"
"generator expression.\n"
"\n"
"Recursive calculations: << expr : start, seq >>\n"
"\n"
"Comments start with '#' and continue until end of line.\n"
},
{ "examples",
"\n"
"Copy stdin to stdout:\n"
" @\n\n"
"Count the number of lines in a file:\n"
" count(@)\n\n"
"Math:\n"
" cos(1)**2 + sin(1)**2\n\n"
"Output matches of a regex:\n"
" [ grep(@, \"[a-zA-Z]+\") ]\n\n"
"Number the lines in a file:\n"
" zip(count(), @)\n\n"
"Count the number of words in a file:\n"
" count(:[ grep(@, \"\\\\S+\") ])\n\n"
"Find a list of unique words in a file:\n"
" { @ : :[ grep(@,\"\\\\S+\") ] }\n\n"
"Output lines matching a regex:\n"
" ?[ grepif(@, \"this\"), @ ]\n\n"
"Tally the frequency of each word in a file:\n"
" { @ -> sum.1 : :[ grep(@, \"\\\\S+\") ] }\n\n"
"A histogram of word count by word length:\n"
" freq={ count.@ -> sum.1 : :[ grep(@, \"\\\\S+\") ] }, sort.freq\n\n"
"Count the number of unique lines:\n"
" merge.[ uniques.@ ]\n\n"
"Glue every pair of lines in a file together:\n"
" [ join(head(@, 2), \"\\t\") : explode.@ ]\n\n"
"Calculate the factorial:\n"
" << @~0 * @~1 : 1, count.@ >>\n"
},
{"threads",
"\n"
"Use the '-t' command-line option to evaluate your expression using\n"
"multiple threads. If you have a multi-core machine, then you will see\n"
"a significant speedup. Parallel evaluation is done map/reduce style: N\n"
"threads will run a CPU-intensive evaluation, while one dedicated\n"
"thread will collect the results of all other threads, aggregate them,\n"
"and output the final answer. Separate the 'scatter' CPU-intensive\n"
"expression from the 'gather' aggregation expression with a special\n"
"'-->' token. If a 'gather' expression is not specified, then a default\n"
"\"@\" will be automatically assumed.\n"
"\n"
"Examples:\n"
"\n"
"Output all four-digit numbers, multithreaded-style:\n"
" :[grep(@,'[0-9]{4}')]\n\n"
"Count the total number of four-digit numbers:\n"
" count.:[grep(@,'[0-9]{4}')] --> sum.@\n\n"
"Find the most popular four-digit number:\n"
" { @ -> sum.1 ::[grep(@,'[0-9]{4}')] } --> (sort.flip.@)[-1]\n"
},
{ "functions",
"\nabs add and array avg box bytes case cat ceil combo cos count cut date datetime\n"
"e eq exp explode file filter find findif first flatten flip floor get glue gmtime\n"
"grep grepif has hash head hex hist if iarray index int join lines log lsh map\n"
"max mean merge min mul ngrams normal now open or pairs peek pi product rand real\n"
"recut replace resplit reverse round rsh sample second seq sin skip sort sorted\n"
"split sqrt stddev stdev string sum take tan tabulate time tolower toupper triplets\n"
"tuple uint unflatten uniques uniques_estimate until url_getparam var variance while zip\n"
},
{"abs",
"\n"
"Computes absolute value.\n"
"\n"
"Usage:\n"
"\n"
"abs Int -> Int\n"
"\n"
"abs Real -> Real\n"
},
{"and",
"Returns 1 if all the arguments are not 0, returns 0 otherwise.\n"
"Equivalent to 'a & b & c ...'. See also 'or'.\n"
"\n"
"Usage:\n"
"\n"
"and (Integer, Integer...) -> UInt\n"
},
{"array",
"\n"
"Stores a sequence or map or atomic value into an array. See also\n"
"'sort' for a version of this function with sorting. See also: 'iarray'.\n"
"\n"
"Usage:\n"
"\n"
"array Map[a,b] -> Arr[(a,b)]\n"
"\n"
"array Seq[a] -> Arr[a]\n"
"\n"
"array a, ... -> Arr[a]\n"
" returns an array with the input elements.\n"
"\n"
"Note: when arrays are used as values in a map, they will concatenate. \n"
},
{"avg",
"\n"
"Synonym for 'mean'.\n"
},
{"box",
"\n"
"Remembers a value. Returns a 'box', which is a tuple of one\n"
"remembered value. Stores the second argument in the box if the box is\n"
"empty. If the box is not empty and the first argument is not zero,\n"
"then replaces the value in the box with the second argument.\n"
"\n"
"Usage:\n"
"\n"
"box UInt, a -> (a,)\n"
},
{"bucket",
"\n"
"Return a bucket key. bucket(x, a, b, n) will split the interval [a, b]\n"
"into n equal sub-intervals and return x rounded down to the nearest\n"
"sub-interval lower bound. Useful for making histograms. See also:\n"
"'hist'.\n"
"\n"
"Usage:\n"
"\n"
"bucket Number, Number, Number, UInt -> Number\n"
" the first three arguments must be the same numeric type.\n"
},
{"bytes",
"\n"
"Accepts a string and returns an array of integers representing the\n"
"bytes in the string. Warning: this function is not Unicode-aware and\n"
"assumes the string is an ASCII bytestream.\n"
"\n"
"Usage:\n"
"\n"
"bytes String -> Arr[UInt]\n"
},
{"case",
"\n"
"A switch/case function. The first argument is compared to every\n"
"argument at position n+1, and if they compare equal, the argument at\n"
"position n+2 is returned. If none match equal, then the last argument\n"
"is returned. See also: 'if'.\n"
"\n"
"Example: [ case(int.@; 1,'a'; 2,'b'; 'c') : count(4) ] returns a b c c.\n"
"\n"
"Usage:\n"
"\n"
"case a,a,b,...,b -> b\n"
},
{"cat",
"\n"
"Concatenates strings.\n"
"\n"
"Usage:\n"
"\n"
"cat String,... -> String. At least one string argument is required.\n"
},
{"ceil",
"\n"
"Rounds a floating-point number to the smallest integer that is greater\n"
"than the input value.\n"
"\n"
"Usage:\n"
"\n"
"ceil Real -> Real\n"
},
{"combo",
"\n"
"Given several arrays, returns a sequence of all combinations of elements\n"
"from those arrays. See also: 'zip'.\n"
"\n"
"Example: 'combo(array(0,1), array(0,1))' returns a sequence of all possible\n"
"pairs of bits.\n"
"\n"
"Usage:\n"
"\n"
"combo Arr[Number], ... -> Seq[(Number,...)]\n"
"combo Arr[String], ... -> Seq[(String,...)]\n"
},
{"cos",
"\n"
"The cosine function.\n"
"\n"
"Usage:\n"
"\n"
"cos Number -> Real\n"
},
{"count",
"\n"
"Counts the number of elements.\n"
"\n"
"Usage:\n"
"\n"
"count None -> Seq[UInt]\n"
" returns an infinite sequence that counts from 1 to infinity.\n"
"\n"
"count UInt -> Seq[UInt]\n"
" returns a sequence that counts from 1 to the supplied argument.\n"
"\n"
"count Number, Number, Number\n"
" returns a sequence of numbers from a to b with increment c. All three\n"
" arguments must be the same numeric type.\n"
"\n"
"count String -> UInt\n"
" returns the number of bytes in the string.\n"
"\n"
"count Seq[a] -> UInt\n"
" returns the number of elements in the sequence. (Warning: counting the\n"
" number of elements will consume the sequence!)\n"
"\n"
"count Map[a] -> UInt\n"
" returns the number of keys in the map.\n"
"\n"
"count Arr[a] -> UInt\n"
" returns the number of elements in the array.\n"
},
{"cut",
"\n"
"Splits a string using a delimiter. See also 'recut' for splitting with\n"
"a regular expression.\n"
"\n"
"Usage:\n"
"\n"
"cut String, String -> Arr[String]\n"
" returns an array of strings, such that the first argument is split\n"
" using the second argument as a delimiter.\n"
"\n"
"cut String, String, Integer -> String\n"
" calling cut(a,b,n) is equivalent to cut(a,b)[n], except much faster.\n"
"\n"
"cut Seq[String], String -> Seq[Arr[String]]\n"
" equivalent to [ cut(@,delim) : seq ].\n"
},
{"date",
"\n"
"Converts a UNIX timestamp to a textual representation of a UTC date.\n"
"\n"
"Usage:\n"
"\n"
"date Int -> String\n"
" returns a UTC date in the \"YYYY-MM-DD\" format.\n"
},
{"datetime",
"\n"
"Converts a UNIX timestamp to a textual representation of a UTC date\n"
"and time.\n"
"\n"
"Usage:\n"
"\n"
"datetime Int -> String\n"
" returns a UTC date and time in the \"YYYY-MM-DD HH:MM:SS\" format.\n"
},
{"e",
"\n"
"Returns the number e.\n"
"\n"
"Usage:\n"
"\n"
"e None -> Real\n"
},
{"eq",
"\n"
"Checks values for equality. If the first argument is equal to any of\n"
"the other arguments, returns 1. Otherwise returns 0.\n"
"\n"
"Usage:\n"
"\n"
"eq a, a, ... -> UInt\n"
},
{"exp",
"\n"
"The exponentiation function. Calling exp(a) is equivalent to e()a.\n"
"\n"
"Usage:\n"
"\n"
"exp Number -> Real\n"
},
{"explode",
"\n"
"Makes a sequence of sequences from a plain sequence: given an input\n"
"sequence, returns that sequence for every element in it. Equivalent to\n"
"x=@, [ glue(@, x) ].\n"
"\n"
"Usage:\n"
"\n"
"explode Seq[a] -> Seq[Seq[a]]\n"
},
{"file",
"\n"
"Opens a file and returns the lines in the file as a sequence of\n"
"strings. (This allows a tab expression to process several files\n"
"instead of just one.)\n"
"\n"
"Usage:\n"
"\n"
"file String -> Seq[String]\n"
},
{"filter",
"\n"
"Filters a sequence by returning an equivalent sequence but with\n"
"certain elements removed. The input is a sequence of tuples where\n"
"the first element is an integer; the output is a sequence with the\n"
"rest of the tuple, filtered on condition that the first element is\n"
"not 0. See also: 'while', 'until'.\n"
"\n"
"Usage:\n"
"\n"
"filter Seq[(Integer,a...) -> Seq[(a...)]\n"
},
{"find",
"\n"
"Finds a substring match in a string. The first argument is the string\n"
"to search in, the second argument is the substring. Returns an array\n"
"of one element containing the substring if found, and an empty array\n"
"otherwise. See also: 'grep', 'grepif', 'findif' for the rationale.\n"
"\n"
"Usage:\n"
"\n"
"find String, String -> Arr[String]\n"
},
{"findif",
"\n"
"Filter strings that contain a substring.\n"
"See also: 'grep', 'grepif', 'find'.\n"
"\n"
"Usage:\n"
"\n"
"findif String, String -> UInt\n"
" returns 1 if the first argument contains the second argument as a\n"
" substring, 0 otherwise. Equivalent to count(find(a,b)) != 0u, except\n"
" much faster.\n"
"\n"
"findif Seq[String], String -> Seq[String]\n"
" returns a sequence of only those strings that have a substring match.\n"
" Equivalent to ?[ findif(@,b), @ : a ].\n"
},
{"first",
"\n"
"Return the first element in a pair, map or sequence or pairs. See\n"
"also: 'second'.\n"
"\n"
"Usage:\n"
"\n"
"first a,b -> a\n"
"first Map[a,b] -> Seq[a]\n"
"first Seq[(a,b)] -> Seq[a]\n"
},
{"flatten",
"\n"
"Flattens a sequence of sequences, a sequence of arrays or a sequence\n"
"of maps into a sequence of values.\n"
"\n"
"Usage:\n"
"\n"
"flatten Seq[ Seq[a] ] -> Seq[a]\n"
"\n"
"flatten Seq[ Arr[a] ] -> Seq[a]\n"
"\n"
"flatten Seq[ Map[a,b] ] -> Seq[(a,b)]\n"
"\n"
"flatten Seq[a] -> Seq[a]\n"
" sequences that are already flat will be returned unchanged. (Though at\n"
" a performance cost.)\n"
},
{"flip",
"\n"
"Given a sequence of pairs or a map, returns a sequence where the pair\n"
"elements are swapped.\n"
"\n"
"Usage:\n"
"\n"
"flip Seq[(a,b)] -> Seq[(b,a)]\n"
"\n"
"flip Map[a,b] -> Seq[(b,a)]\n"
},
{"floor",
"\n"
"Rounds a floating-point number to the greatest integer that is less\n"
"than the input value.\n"
"\n"
"Usage:\n"
"\n"
"floor Real -> Real\n"
},
{"get",
"\n"
"Accesses map or array elements (like 'index'), but returns a default\n"
"value if the key is not found in the map or if the index is out of\n"
"bounds. (Unlike 'index' which throws an exception.)\n"
"\n"
"Usage:\n"
"\n"
"get Map[a,b], a, b -> b\n"
" returns the element stored in the map with the given key, or the third\n"
" argument if the key is not found.\n"
"\n"
"get Arr[a], UInt, a -> a\n"
" returns the element at the given index, or the third argument if the\n"
" index is out of bounds.\n"
},
{"glue",
"\n"
"Adds an element to the head or tail of a sequence. glue(1, seq(2, 3)) is\n"
"equivalent to seq(1, 2, 3). See also: 'take', 'peek'.\n"
"\n"
"Usage:\n"
"\n"
"glue a, Seq[a] -> Seq[a]\n"
"\n"
"glue Seq[a], a -> Seq[a]\n"
},
{"gmtime",
"\n"
"Converts a UNIX timestamp to a UTC date and time.\n"
"\n"
"Usage:\n"
"\n"
"gmtime Int -> Int, Int, Int, Int, Int, Int\n"
" returns year, month, day, hour, minute, second.\n"
},
{"grep",
"\n"
"Finds regular expression matches in a string. The first argument is\n"
"the string to match in, the second argument is the regular\n"
"expression. Matches are returned in an array of strings. Regular\n"
"expressions use ECMAScript syntax. See also: 'grepif', 'find', 'findif'.\n"
"\n"
"Usage:\n"
"\n"
"grep String, String -> Arr[String]\n"
},
{"grepif",
"\n"
"Filter strings according to a regular expression.\n"
"See also: 'grep', 'find', 'findif'.\n"
"\n"
"Usage:\n"
"\n"
"grepif String, String -> UInt\n"
" returns 1 if a regular expression has matches in a string, 0\n"
" otherwise. Equivalent to count(grep(a,b)) != 0u, except much faster.\n"
"\n"
"grepif Seq[String], String -> Seq[String]\n"
" returns a sequence of only those strings that have regular expression\n"
" matches. Equivalent to ?[ grepif(@,b), @ : a ].\n"
},
{"has",
"\n"
"Checks for existence in a map or array.\n"
"\n"
"Usage:\n"
"\n"
"has Map[a,b], a -> UInt\n"
" returns 1 if a key exists in the map, 0 otherwise. The first argument is\n"
" the map, the second argument is the key to check.\n"
"\n"
"has Arr[a], a -> UInt\n"
" returns 1 if a value is in the array, 0 otherwise. The first argument is\n"
" the array, the second argument is the value. Equivalent to \n"
" has(map.zip(seq.a, count()), b).\n"
},
{"hash",
"\n"
"Hashes a value to an unsigned integer. The FNV hash function (32 or\n"
"64 bit depending on CPU architecture) is used.\n"
"\n"
"Usage:\n"
"\n"
"hash a -> UInt\n"
},
{"head",
"\n"
"Accepts a sequence or array and returns an equivalent sequence that is\n"
"truncated to be no longer than N elements. See also: 'skip', 'stripe'.\n"
"\n"
"Usage:\n"
"\n"
"head Seq[a], UInt -> Seq[a]\n"
"\n"
"head Arr[a], UInt -> Seq[a]\n"
},
{"hex",
"\n"
"Marks the given unsigned integer such that it is output in hexadecimal.\n"
"\n"
"Usage:\n"
"\n"
"hex UInt -> UInt\n"
},
{"hist",
"\n"
"Accepts an array of numbers and a bucket count and returns an array of\n"
"tuples representing a histogram of the values in the array. (The\n"
"interval between the maximum and minimum value is split into N equal\n"
"sub-intervals, and a number of values that falls into each\n"
"sub-interval is tallied.) The return value is an array of pairs:\n"
"(sub-interval lower bound, number of elements). See also: 'bucket'.\n"
"\n"
"Usage:\n"
"\n"
"hist Arr[Number], UInt -> Arr[(Real,UInt)]\n"
},
{"iarray",
"\n"
"Exactly equivalent to 'array', except when printing the elements will\n"
"be separated with a ';' instead of a newline.\n"
"\n"
"Usage:\n"
"\n"
"iarray Map[a,b] -> Arr[(a,b)]\n"
"\n"
"iarray Seq[a] -> Arr[a]\n"
"\n"
"iarray a, ... -> Arr[a]\n"
"\n"
"iarray Arr[a] -> Arr[a]\n"
},
{"if",
"\n"
"Choose between alternatives. If the first integer argument is not 0,\n"
"then the second argument is returned; otherwise, the third argument is\n"
"returned. The second and third arguments must have the same type.\n"
"\n"
"Note: this is not a true conditional control structure, since all\n"
"three arguments are always evaluated.\n"
"\n"
"Usage:\n"
"\n"
"if Integer, a, a -> a\n"
"if Integer, a -> a\n"
" this alternative form throws an error if the first integer argument is 0.\n"
" Useful for error checking or for sequences with the 'try' clause."
},
{"index",
"\n"
"Select elements from arrays, maps or tuples. Indexing a non-existent\n"
"element will cause an error.\n"
"\n"
"Usage:\n"
"\n"
"index Arr[a], UInt -> a\n"
" returns element from the array, using a 0-based index.\n"
"\n"
"index Arr[a], Int -> a\n"
" negative indexes select elements from the end of the array, such that\n"
" -1 is the last element, -2 is second-to-last, etc.\n"
"\n"
"index Arr[a], Real -> a\n"
" returns an element such that 0.0 is the first element of the array and\n"
" 1.0 is the last.\n"
"\n"
"index Map[a,b], a -> b\n"
" returns the element stored in the map with the given key. It is an\n"
" error if the key is not found; see 'get' for a version that returns a\n"
" default value instead.\n"
"\n"
"index (a,b,...), UInt\n"
" returns an element from a tuple.\n"
"\n"
"index Arr[a], Number, Number -> Arr[a]\n"
" returns a sub-array from an array; the start and end elements of the\n"
" sub-array are indexed as with the two-argument version of 'index'.\n"
"\n"
"index String, Integer, Integer -> String\n"
" returns a substring from a string, as with the array slicing\n"
" above. Note: string indexes refer to bytes, tab is not Unicode-aware.\n"
},
{"int",
"\n"
"Converts an unsigned integer, floating-point value or string into a\n"
"signed integer.\n"
"\n"
"Usage:\n"
"\n"
"int UInt -> Int\n"
"\n"
"int Real -> Int\n"
"\n"
"int String -> Int\n"
"\n"
"int String, Integer -> Int\n"
" tries to convert the string to an integer; if the conversion fails,\n"
" returns the second argument instead.\n"
},
{"join",
"\n"
"Concatenates the elements in a string array or sequence using a\n"
"delimiter.\n"
"\n"
"Usage:\n"
"\n"
"join Arr[String], String -> String\n"
"\n"
"join Seq[String], String -> String\n"
"\n"
"join String, Arr[String], String, String -> String\n"
" adds a prefix and suffix as well. Equivalent to cat(p, join(a, d), s).\n"
"\n"
"join String, Seq[String], String, String -> String\n"
},
{"lines",
"\n"
"Returns its arguments as a tuple, except that each element will be printed\n"
"on its own line. See also: 'tuple'.\n"
"\n"
"Usage:\n"
"\n"
"lines (a,b,...) -> (a,b,...)\n"
},
{"log",
"\n"
"The natural logarithm function.\n"
"\n"
"Usage:\n"
"\n"
"log Number -> Real\n"
},
{"lsh",
"\n"
"Bit shift left; like the C << operator. (See also 'rsh'.)\n"
"\n"
"Usage:\n"
"\n"
"lsh Int, Integer -> Int\n"
"lsh UInt, Integer -> UInt\n"
},
{"map",
"\n"
"Stores a sequence of pairs or a single pair into a map.\n"
"\n"
"Usage:\n"
"\n"
"map Seq[(a,b)] -> Map[a,b]\n"
"\n"
"map (a,b) -> Map[a,b]\n"
" returns a map with one element.\n"
"\n"
"Note: when maps are used as values in other maps, they will merge. \n"
},
{"max",
"\n"
"Finds the maximum element in a sequence or array. See also: 'min'.\n"
"\n"
"Usage:\n"
"\n"
"max Arr[a] -> a\n"
"\n"
"max Seq[a] -> a\n"
"\n"
"max Number -> Number\n"
" Note: this version of this function will mark the return value to\n"
" calculate the max when stored as a value into an existing key of a\n"
" map.\n"
},
{"mean",
"\n"
"Calculates the mean (arithmetic average) of a sequence or array of\n"
"numbers. See also: 'var' and 'stdev'.\n"
"\n"
"Usage:\n"
"\n"
"mean Arr[Number] -> Real\n"
"\n"
"mean Seq[Number] -> Real\n"
"\n"
"mean Number -> Real\n"
" Note: this version of this function will mark the returned value to\n"
" calculate the mean when stored as a value into an existing key of a\n"
" map.\n"
},
{"merge",
"\n"
"Aggregates a sequence of values. 'merge(a)' is equivalent to\n"
"'{ 1 -> @ : a }~1', except faster.\n"
"\n"
"Usage:\n"
"\n"
"merge Seq[a] -> a\n"
},
{"min",
"\n"
"Finds the minimum element in a sequence or array. See also: 'max'.\n"
"\n"
"Usage:\n"
"\n"
"min Arr[a] -> a\n"
"\n"
"min Seq[a] -> a\n"
"\n"
"min Number -> Number\n"
" Note: this version of this function will mark the return value to\n"
" calculate the min when stored as a value into an existing key of a\n"
" map.\n"
},
{"mul",
"\n"
"Multiplies the arguments. Equivalent to 'product.seq(...)'\n"
"See also 'add', 'sum', 'product'.\n"
"\n"
"Usage:\n"
"mul Number, ... -> Number\n"
},
{"ngrams",
"\n"
"Similar to 'pairs' and 'triplets', except returns a sequence of arrays\n"
"of length N instead of tuples.\n"
"\n"
"Usage:\n"
"\n"
"ngrams Seq[a], UInt -> Seq[Arr[a]]\n"
},
{"normal",
"\n"
"Returns random numbers from the normal (gaussian) distribution. (See\n"
"also: 'rand', 'sample'.)\n"
"\n"
"Usage:\n"
"\n"
"normal None -> Real\n"
" returns a random number with mean 0 and standard deviation 1.\n"
"\n"
"normal Real, Real -> Real\n"
" same, but with mean and standard deviation of a and b.\n"
},
{"now",
"\n"
"Returns the current UNIX timestamp.\n"
"\n"
"Usage:\n"
"\n"
"now None -> Int\n"
},
{"open",
"\n"
"Same as 'file'.\n"
},
{"or",
"\n"
"Returns 0 if all the arguments are 0, returns 1 otherwise.\n"
"Equivalent to 'a | b | c ...'. See also 'and'.\n"
"\n"
"Usage:\n"
"\n"
"or (Integer, Integer...) -> UInt\n"
},
{"pairs",
"\n"
"Given a sequence, return a sequence of pairs of the previous sequence\n"
"element and the current sequence element. Example: given [ 1, 2, 3, 4 ]\n"
"will return [ (1, 2), (2, 3), (3, 4) ]. (See also: 'triplets' and\n"
"'ngrams'.)\n"
"\n"
"Usage:\n"
"\n"
"pairs Seq[a] -> Seq[(a,a)]\n"
},
{"peek",
"\n"
"Given a sequence, return a pair of its first element and the sequence\n"
"itself with the first element reattached. Equivalent to 'h=take.@, h, glue(h, @)'.\n"
"See also: 'take', 'glue'.\n"
"\n"
"Usage:\n"
"\n"
"peek Seq[a] -> (a, Seq[a])\n"
},
{"pi",
"\n"
"Return the number pi.\n"
"\n"
"Usage:\n"
"\n"
"pi None -> Real\n"
},
{"product",
"\n"
"Computes a product of the elements of a sequence or array.\n"
"See also 'sum', 'add', 'mul'. \n"
"\n"
"Usage:\n"
"product Arr[Number] -> Number\n"
"product Seq[Number] -> Number\n"
"product Number -> Number\n"
" this version of this function will mark the value to be aggregated as\n"
" a sum when stored as a value into an existing key of a map.\n"
},
{"rand",
"\n"
"Returns random numbers from the uniform distribution. (See also:\n"
"'normal', 'sample'.)\n"
"\n"
"Usage:\n"
"\n"
"rand None -> Real\n"
" returns a random real number from the range [0, 1).\n"
"\n"
"rand Real, Real -> Real\n"
" same, but with the range [a, b).\n"
"\n"
"rand UInt, UInt -> UInt\n"
"\n"
"rand Int, Int -> Int\n"
" returns a random number from the integer range [a, b].\n"
},
{"real",
"\n"
"Converts an unsigned integer, signed integer or string into a\n"
"floating-point value.\n"
"\n"
"Usage:\n"
"\n"
"real UInt -> Real\n"
"\n"
"real Int -> Real\n"
"\n"
"real String -> Real\n"
"\n"
"real String, Real -> Real\n"
" tries to convert the string to a floating-point value; if the\n"
" conversion fails, returns the second argument instead.\n"
},
{"recut",
"\n"
"Splits a string using a regular expression. See also 'cut' for\n"
"splitting with a byte string.\n"
"\n"
"recut String, String -> Arr[String]\n"
" returns an array of strings, such that the first argument is split\n"
" using the second argument as a regular expression delimiter.\n"
"\n"
"recut String, String, UInt -> String\n"
" calling recut(a,b,n) is equivalent to recut(a,b)[n], except faster.\n"
"\n"
"recut Seq[String], String -> Seq[Arr[String]]\n"
" equivalent to [ recut(@,delim) : seq ].\n"
},
{"replace",
"\n"
"Search-and-replace in a string with regexes. The first argument is the\n"
"string to search, the second argument is the regex, and the third\n"
"argument is the replacement string. Regex and replacement string use\n"
"ECMAScript syntax.\n"
"\n"
"Usage:\n"
"\n"
"replace String, String, String -> String\n"
},
{"resplit",
"\n"
"A synonym for 'recut'.\n"
},
{"reverse",
"\n"
"Reverses the elements in an array.\n"
"\n"
"Usage:\n"
"\n"
"reverse Arr[a] -> Arr[a]\n"
},
{"round",
"\n"
"Rounds a floating-point number to the nearest integer.\n"
"\n"
"Usage:\n"
"\n"
"round Real -> Real\n"
},
{"rsh",
"\n"
"Bit shift right; like the C >> operator. (See also 'lsh'.)\n"
"\n"
"Usage:\n"
"\n"
"rsh Int, Integer -> Int\n"
"\n"
"rsh UInt, Integer -> UInt\n"
},
{"sample",
"\n"
"Sample from a sequence of atomic values, without replacement. (See\n"
"also: 'rand', 'normal'.)\n"
"\n"
"Usage:\n"
"\n"
"sample UInt, Seq[a] -> Arr[a]\n"
" the first argument is the sample size.\n"
},
{"second",
"\n"
"Return the second element in a pair, map or sequence or pairs. See\n"
"also: 'first'.\n"
"\n"
"Usage:\n"
"\n"
"second a,b -> b\n"
"\n"
"second Map[a,b] -> Seq[b]\n"
"\n"
"second Seq[(a,b)] -> Seq[b]\n"
},
{"seq",
"\n"
"Accepts values of the same type and returns a sequence of\n"
"those values. (A synonym for 'tabulate'.)\n"