-
Notifications
You must be signed in to change notification settings - Fork 9
/
syntax-across-languages.html.pl
executable file
·5305 lines (4813 loc) · 168 KB
/
syntax-across-languages.html.pl
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
use strict;
use vars qw(@static @dynamic @OO @functional @reflexive @typed @rare @has_lambda @various);
########################################################################################
# kinds ################################################################################
########################################################################################
my @OO_dynamic =
qw(E JavaScript Perl Perl6 MSH PHP Python Rebol Ruby Smalltalk Io VisualBasic YCP Tcl MzScheme Oz Scilab Matlab Julia CoffeeScript);
my @OO_static =
('C#', qw(Ada Beta C++ Cecil D Pike Objective-C Java Eiffel Sather Delphi-Kylix Pliant Simula));
my @functional_dynamic =
qw(Scheme Erlang FL Logo);
my @functional_static =
qw(Mercury SML Haskell);
@static = (@OO_static, @functional_static,
qw(C Cobol Pascal Fortran merd Modula-2 Modula-3 OCaml Go), 'F#');
@dynamic = (@functional_dynamic, @OO_dynamic,
qw(Awk Basic Dylan Forth Maple Lua Icon XPath XSLT Pike PostScript Prolog BourneShell FishShell Oz EmacsLisp CommonLisp ClassicREXX Yorick Vimscript));
@OO = (@OO_dynamic, @OO_static,
qw(OCaml CommonLisp Dylan merd));
@functional = (@functional_dynamic, @functional_static,
qw(OCaml EmacsLisp CommonLisp Dylan merd Smalltalk));
@reflexive = (@dynamic,
qw(Java merd Pliant));
@typed = (@static,
qw(Dylan Smalltalk Perl6 VisualBasic YCP));
@has_lambda = (@functional,
qw(Ruby Python Perl Perl6 MSH Mathematica JavaScript CoffeeScript), 'C#2', 'C#3', 'Tcl');
@various = qw(APL BCPL B J PL/I MUMPS HTML CSS TeX SGML XML YAML Assembler SQL92 GNU-sed GNU-bc);
my %kind_dependencies = (
reflexive => 'dynamic',
typed => 'static',
has_lambda => 'functional',
);
my %kind_descriptions = (
static => 'Statically typed',
dynamic => 'Dynamically typed',
OO => 'Object Oriented',
functional => 'Functional',
reflexive => 'Reflexive',
typed => 'Has types',
has_lambda => 'Has anonymous functions',
);
my %kinds = map { $_ => \@{$::{$_}} } (qw(rare various), keys %kind_descriptions);
my %hierarchy = (
'Fortran90' => ['Fortran'],
'C99' => ['C'],
'C++-0x' => ['C++'],
'C#2' => ['C#'],
'C#3' => ['C#2', 'C#'],
'SQL99' => ['SQL92'],
'Delphi-Kylix' => ['Pascal'],
'Objective-C' => ['C'],
'VisualBasic' => ['Basic'],
'PHP5' => ['PHP'],
'SML-NJ' => ['SML'],
'Scheme-SRFI1' => ['Scheme'],
'Scheme-SRFI28' => ['Scheme'],
'Scheme-SRFI34' => ['Scheme'],
'MzScheme' => ['Scheme-SRFI1', 'Scheme-SRFI28','Scheme'],
'Squeak' => ['Smalltalk'],
'XSLT' => ['XPath', 'XML'],
'Tcl8.5' => ['Tcl'],
'KornShell' => ['BourneShell'],
'CoffeeScript' => ['JavaScript'],
);
# complete kinds using the hierarchy of languages
# and fill_in rev_hierarchy
my %rev_hierarchy;
while (my ($l, $subls) = each %hierarchy) {
foreach my $subl (@$subls) {
push @{$rev_hierarchy{$subl}}, $l;
next if @$subls > 1;
foreach (values %kinds) {
push @$_, $l if member($subl, @$_);
}
}
}
my @langs = uniq(map { @$_ } values %kinds);
########################################################################################
# main #################################################################################
########################################################################################
my $all_raw = [
'Various' => [
'commenting' =>
[
'until end of line' =>
[
'#' => "Perl Io Perl6 Maple Ruby Python Tcl Icon Awk FishShell Julia BourneShell PHP merd E Pliant YAML GNU-sed GNU-bc CoffeeScript",
'//' => "BCPL Io C99 C++ C# F# Java Dylan Pike PHP JavaScript YCP Yorick Scilab Go",
'--' => "Cecil Eiffel Sather Simula Haskell Ada Lua SQL92",
';' => "EmacsLisp Logo CommonLisp Scheme Rebol Assembler MUMPS",
'%' => "Prolog Mercury TeX Erlang PostScript Oz Matlab",
'rem' => "Basic",
"'" => "VisualBasic",
'"' => "Vimscript",
'\\' => "Forth",
'!' => "Fortran90 Assembler",
'NB.' => 'J',
'C or * in column 1' => "Fortran",
],
'nestable' =>
[
'(* ... *)' => "OCaml Beta F# Mathematica Pascal Modula-3 SML",
'%( ... %)' => "Matlab",
'/* ... */' => "Oz Io Dylan ClassicREXX SQL99",
'{ ... }' => "Pascal Rebol",
'{- ... -}' => "Haskell",
'#| ... |# (introduced in Scheme in R6RS)' => "CommonLisp Scheme",
'#= ... =#' => "Julia",
'#[ ... ]' => "Perl6",
'#if 0 ... #endif' => "C",
'comment { ... }' => "Rebol",
'comment [ ... ]' => "Rebol",
'[ ... ] (when unused)' => "Rebol",
'--[[ ... ]]' => "Lua",
],
'non nestable' =>
[
'" ... "' => "Smalltalk",
'/* ... */' => "C C++ C# Java B PL/I Pike CSS PHP JavaScript Mercury YCP Yorick GNU-bc Go",
'<!-- ... -->' => "HTML XML",
'( ... )' => "Forth",
pre("###\n...\n###") => "CoffeeScript",
],
],
'documentation comment' =>
[ { MLANG => "C Tcl Forth ClassicREXX Mathematica Logo MUMPS Prolog Maple Go" },
'until end of line' =>
[
'///' => "C# F# Java",
'-- |' => "Haskell",
'-- ^' => "Haskell",
],
'non nestable' =>
[
"/** ... */ (for C, it is not a standard convention, but it is the more widespread)" => "C C# Java JavaScript E PHP",
"(** ... *)" => "F#",
],
'' =>
[
'{-| ... -}' => "Haskell",
'(** ... *)' => "OCaml",
'/* DOCUMENT ... */' => "Yorick",
'indexing
identifier: "...";' => "Eiffel",
"someClass comment: '...'" => "Smalltalk",
'rebol [ Note: "..." ]' => "Rebol",
'func ["..." arg] ...' => "Rebol",
pre('class X:
"""...
"""
def x():
"""...
"""
') . " (any string literal would work)" => "Python",
'(define (f para1 para2) "..." ...)' => "Scheme",
'(defun f (para1 para2) "..." ...)' => "EmacsLisp CommonLisp",
pre('=pod
...
=cut') . " (see also =head1, =head2, =over, etc)" => "Perl Perl6",
pre('=begin
...
=end') => "Ruby",
pre('function MYFUNCTION
%MYFUNCTION the very first comment line is displayed in the help table of contents
%
% the remaining lines are displayed when getting help for MYFUNCTION
%
') => "Matlab",
],
],
'information about the current line and file' =>
[ { MLANG => "OCaml Io Haskell Forth Ada MUMPS CommonLisp Matlab Prolog Tcl" },
'__LINE__ __FILE__' => "C C++ Perl Pike PHP Ruby",
'__LINE__ __SOURCE_FILE__' => "F#",
'$?LINE $?FILE' => "Perl6",
'__file__' => "Python",
pre('(new System.Diagnostics.StackFrame(true)).GetFileLineNumber()
(new System.Diagnostics.StackFrame(true)).GetFileName()') => 'C#',
pre('Thread.currentThread().getStackTrace()[1].getLineNumber();
Thread.currentThread().getStackTrace()[1].getFileName();') => "Java",
'system/script/header/file (need "file: %script-header.r" in file header)' => "Rebol",
'SOURCELINE() / parse source OS . SOURCENAME' => "ClassicREXX",
'info frame 0' => "Tcl8.5",
'thisContext lineNumber / thisContext method source' => "Smalltalk",
'runtime.Caller(0)' => 'Go',
],
'tokens' =>
[ { ALL => 1 },
'case-sensitivity (keywords, variable identifiers...)' =>
[ # see http://www.swiss.ai.mit.edu/~jaffer/r5rs_4.html#SEC14 for Scheme, Guile is an exception
'case-sensitive' => 'B C C++ C# F# Io Java Maple Mathematica Prolog JavaScript Lua Matlab Pike Perl Perl6 Python Ruby XML YAML Tcl Smalltalk BourneShell FishShell OCaml Haskell merd Awk Modula-3 Pliant Yorick CoffeeScript Go',
'case-insensitive' => "PL/I CSS Pascal Logo Rebol VisualBasic Eiffel Ada SGML HTML CommonLisp Forth Assembler ClassicREXX SQL92",
'case-sensitive: variables<br>case-insensitive: keywords, functions, constants...' => "PHP",
'case-sensitive: identifiers<br>case-insensitive: keywords' => "E",
'case-sensitive: identifiers<br>case-insensitive: commands' => "MUMPS",
'case-sensitive: upper case disallowed' => 'GNU-bc',
],
'what is the standard way for <a href="http://c2.com/cgi/wiki?CapitalizationRules">scrunching together multiple words</a>' =>
[ { MLANG => 'MUMPS' },
# see http://dotnet.di.unipi.it/EcmaSpec/CSharp/cont25.html C.1.4 for C#
# perl -ne '$l{$_} = 1 foreach /(\w*[a-z][_]\w*)/g; $m{$_} = 1 foreach /(\w*[a-z][A-Z]\w*)/g; END { print join(" ", keys %l), "\n", join(" ", keys %m), "\n" }'
'camelCase' => "JavaScript CoffeeScript",
'CamelCase or camelCase' => "Haskell Io Java JavaScript Tcl Smalltalk C# E Pascal Mathematica VisualBasic Go",
'underscores' => 'merd FishShell GNU-bc',
'dots' => "Logo",
'hyphens' => "Rebol EmacsLisp CommonLisp Scheme",
'underscores for functions / types, unclear for modules / constructors' => "OCaml",
'UPPER_CASE' => "BourneShell",
'lowercasenoseparator' => 'Matlab',
'underscores, UPPER_CASE for class names' => "Eiffel",
'CamelCase for classes, underscores for methods' => "Python",
'CamelCase for types, underscores for functions, variables, ...' => "Pliant",
'CamelCase for methods, types and modules, underscore for functions' => "F#",
'CamelCase for modules and classes, ALL_CAPS for constants, underscores for functions, variables, ...' => 'Ruby',
'CamelCase for modules and classes, ALLCAPS for macros, underscores for methods, constants and variables' => 'Pike',
'CamelCase for modules, ALL_CAPS for constants, unclear for functions / variables' => "Perl Perl6",
'CamelCase for variables, underscores for predicates' => 'Prolog',
'usually lowercase or underscores, ALL_CAPS for macros' => 'C',
'usually underscores' => "C++",
'Camel_Case' => "Ada",
],
'variable identifier regexp' =>
[
'[a-zA-Z][a-zA-Z0-9]*' => "PL/I Smalltalk FishShell Mathematica",
"[a-zA-Z][_a-zA-Z0-9]*" => "Eiffel Matlab Vimscript",
"[a-zA-Z](_?[a-zA-Z0-9])*" => 'Ada',
"[_a-zA-Z][_a-zA-Z0-9]*" => 'B C C++ C# E Maple Python PHP Tcl Awk Go',
'[_a-zA-Z0-9]+' => "BourneShell Perl Perl6",
'[a-zA-Z0-9]+' => "FishShell",
"[_a-zA-Z][_a-zA-Z0-9]* or '[^']*'" => "Pliant",
'[_a-zA-Z$][_a-zA-Z0-9$]*' => "Java",
'[$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*' => "CoffeeScript JavaScript",
'[a-zA-Z%][a-zA-Z0-9]*' => "MUMPS",
"[_a-z][_a-zA-Z0-9]*" => 'Ruby',
"[_a-z][_a-zA-Z0-9]*[!?']*" => 'merd',
"[_a-z][_a-zA-Z0-9']*" => 'SML OCaml Haskell',
"[_a-zA-Z][_a-zA-Z0-9']*" => 'F#',
"[_A-Z][_a-zA-Z0-9]*" => 'Prolog Mercury',
"[_a-zA-Z!$%&*/:<=>?^][_a-zA-Z!$%&*/:<=>?^0-9.+-]*" => "Scheme", # cooked from http://www.cs.indiana.edu/scheme-repository/R4RS/r4rs_9.html
"[a-zA-Z!?@#$_][a-zA-Z0-9!?@#$_]*" => "ClassicREXX",
q([_a-zA-Z?!.'+*&|=~-][_a-zA-Z0-9?!.'+*&|=~-]* or
<br>[^0-9[](){}":;/][^ \n\t[](){}":;/]*) => "Rebol",
'[a-z][a-z0-9_]*' => "GNU-bc",
'anything without a space and is not a number' => "CommonLisp Forth",
],
'function identifier regexp (if different from variable identifier regexp)' =>
[ { KIND => 'rare' },
"[_a-zA-Z][_a-zA-Z0-9]*[!?]?" => 'Ruby',
"[_a-z][_a-zA-Z0-9]*" => 'Prolog Mercury',
"[A-Z][_a-zA-Z0-9]* (for user defined functions only)" => 'Vimscript',
'[^ \t\n\r\f]+' => "Tcl",
'[^ \t\n\r\f/]+' => "FishShell",
],
'keyword regexp (if different from variable identifier regexp)' =>
[ { KIND => 'rare' },
'[A-Z]+' => "Modula-3",
],
'type regexp (if different from variable identifier regexp)' =>
[ { KIND => 'rare' },
"[_A-Z][_a-zA-Z0-9']*" => 'Haskell',
"[_a-z][_a-zA-Z0-9']*" => 'OCaml Mercury',
],
'constant regexp (if different from variable identifier regexp)' =>
[ { KIND => 'rare' },
"[A-Z][_a-zA-Z0-9]*" => 'Ruby',
"[_A-Z][_a-zA-Z0-9']*" => 'OCaml Haskell',
"[_a-z][_a-zA-Z0-9']*" => 'Mercury',
],
],
'breaking lines (useful when end-of-line and/or indentation has a special meaning)' =>
[ { MLANG => "Pliant MUMPS Prolog GNU-sed" },
'nothing needed' => 'Ada B C C++ C# D F# Haskell PHP Maple Mathematica Eiffel PostScript Rebol Java YCP JavaScript Pascal Perl Perl6 OCaml CommonLisp EmacsLisp Scheme SML Smalltalk XSLT Forth Oz Go',
'\\' => "Awk Io C Python Ruby Tcl E FishShell BourneShell GNU-bc CoffeeScript",
'_' => "VisualBasic",
',' => "ClassicREXX",
'~' => "Logo",
'...' => "Matlab",
],
'variable assignment or declaration' =>
[
'assignment' =>
[
'=' => "B C C++ C# Io Mathematica Java Perl Perl6 Matlab Pike PHP Basic Erlang Icon Oz JavaScript Lua BourneShell Awk YCP ClassicREXX Yorick Go",
':=' => "BCPL Ada SML Cecil Pascal Mathematica Dylan Eiffel Maple Sather Modula-3 Simula Smalltalk E Pliant",
'<-' => "OCaml F#",
'_ (displayed <- with a special character)' => "Squeak",
':' => "BCPL Rebol",
'-> (variable on the right)' => "Beta",
'def' => "PostScript",
'setq' => "EmacsLisp CommonLisp",
'setf' => "CommonLisp",
'set' => "Rebol CommonLisp FishShell",
'SET v=...' => "MUMPS",
'set!' => "Scheme",
'is' => "Prolog",
'make "v e' => "Logo",
'e v !' => "Forth",
],
'declaration' =>
[
'=' => "Haskell Prolog Mercury",
'<-' => "Haskell",
':-' => "Prolog",
':=' => "Io",
'let v = e in' => "F# OCaml",
'let val v = e in' => "SML",
'let v = e (F#: with indentation)' => "F# BCPL Vimscript",
'def v := e / var v := e' => "E",
'my / our / local / use vars' => "Perl",
'my / our / temp' => "Perl6",
'define' => "Dylan Scheme",
'let let*' => "Scheme CommonLisp",
'letrec' => "Scheme",
'flet labels defun defmethod defvar defparameter defsetf ..' => "CommonLisp",
'local V1 = e V2 = e2 in ... end' => "Oz",
'global v1, v2' => "Python",
'global v1 v2' => "Matlab Scilab",
':@' => "Beta",
'NEW v' => "MUMPS",
'v: t' => "Ada Pascal Eiffel",
't v' => "C C++ C# Java",
'var v t' => "Go",
'| v1 v2 |' => 'Smalltalk',
'auto v1, v2; extrn v3, v4;' => "B",
'auto' => "GNU-bc",
'var' => "JavaScript Pliant",
'gvar' => "Pliant",
'variable v (the variable behaves like a pointer)' => "Forth",
'e value v' => "Forth",
'Module[{x, y = v}, ... ]' => 'Mathematica',
'Block[{x, y = v}, ... ]' => 'Mathematica',
'With[{c1 = v1, c2 = v2, ... }, ...]' => 'Mathematica',
'<xsl:variable name="v" select="e"/>' => "XSLT",
],
'both' =>
[
'=' => "Python Ruby merd GNU-bc CoffeeScript",
':=' => "merd Go",
'set, variable' => "Tcl",
],
],
'grouping expressions' =>
[ { MLANG => 'EmacsLisp CommonLisp Scheme XSLT PostScript Forth' },
'( ... )' => "Beta BCPL D Io Julia Logo Mathematica Prolog B ClassicREXX Maple C C++ C# Matlab Scilab YCP Java Eiffel Rebol MUMPS MSH Pike Perl Perl6 Python Ruby Pascal Haskell OCaml F# Smalltalk SML merd E Tcl PHP JavaScript Lua Ada Awk Modula-3 Pliant XPath Oz SQL92 Yorick GNU-bc CoffeeScript Go Vimscript",
'[ ... ]' => "Rebol",
'indentation' => "merd",
'$ ...' => "Haskell",
'begin ... end' => "OCaml F# Ruby FishShell",
'space (cf <a href="http://merd.net/choices_syntax.html#horizontal_layout">horizontal layout</a>)' => "merd",
],
'block (grouping statements, especially when statements are not expressions)' =>
[ { MLANG => 'OCaml Prolog Forth Rebol SML XSLT Mathematica CommonLisp Maple Oz PostScript' },
'{ ... }' => "Pike PHP JavaScript Awk BourneShell Tcl BCPL Yorick GNU-sed GNU-bc",
'{ ... } (introduce scope)' => "B C C++ C# Java Perl Perl6 E Haskell Modula-3 YCP Go",
'( ... ) (introduce scope)' => "BourneShell",
'[ ... ] (Smalltalk: introduce scope)' => "Logo Smalltalk",
'"..."' => "Tcl",
'begin ... end (introduce scope)' => "Pascal Ada",
'(begin ...)' => 'Scheme',
'BEGIN ... END' => "Modula-3",
'do ... end' => "ClassicREXX",
'do ... end (introduce scope)' => "PL/I Lua",
'indentation' => "Python Pliant MUMPS F# CoffeeScript",
'indentation (introduce scope)' => "Haskell merd",
'foo ... end where foo in { if, do, ... }' => "Modula-2 Ruby",
'foo ... end where foo in { if, for, while, ... }' => "Matlab Scilab",
'foo ... end where foo in { if, loop, ... }' => "Eiffel",
'foo ... end foo where foo in { if, do, ... }' => "Fortran90 Ada",
'(* ... *) (ascii representation, original uses a special charset)' => "BCPL",
'(# ... #)' => "Beta",
],
'use a block as a return value (when statements are not expressions)' =>
[ { KIND => 'rare' },
'valof' => "BCPL",
'do' => "Perl Perl6",
"proc() .. end proc" => "Maple",
],
'equality / inequality' =>
[
'shallow' =>
[
'== != ' => "B C C++ Io Java OCaml F# Pike Perl Perl6 Awk Yorick CoffeeScript Go",
'= /=' => "Fortran90 Eiffel",
'= <>' => "Pliant Forth Rebol Logo Maple Modula-2",
'= # (in Modula-2, <> and # are synonyms)' => "Modula-2 Modula-3",
"= !=" => "BourneShell FishShell",
"== === != !== (=== and !== differ from == and != when the objects' type differ)" => "JavaScript PHP",
"=== !==" => "PHP5 Perl6",
'== ~=' => "Lua",
'== ~~' => "Smalltalk",
'== ~==' => "Dylan",
"= '=" => "MUMPS",
'= ~= neqv (ascii representation, original uses a special charset)' => "BCPL",
'f= f<>' => "Forth",
'is_equal (for objects)' => "Eiffel",
'eq ne' => "EmacsLisp PostScript",
'eq, eql' => "CommonLisp",
'eq? eqv?' => "Scheme",
'.EQ. .NE.' => "Fortran",
'is / is not' => "Python",
'is / isnot' => 'Vimscript'
],
'deep' =>
[
'== !=' => "Awk C++ C# E Ruby Tcl merd Python YCP PHP5 Vimscript",
'== <>' => "Python",
'== /=' => "Haskell",
'== \=' => "Oz",
'== \==' => "ClassicREXX Prolog",
'= /=' => "Ada",
'= !=' => "XPath Maple",
'= <>' => "VisualBasic OCaml F# Rebol SML Beta Pascal SQL92",
'= ~=' => "Dylan Smalltalk",
'== ~= eq ne isequal isequalwithequalnans' => "Matlab",
'== ~= eq ne isequal' => "Scilab",
'=@= \=@= / = \= / =:= =\= (normal / structural / unification / arithmetic)' => "Prolog",
'=== =!= / == != (structural / mathematical)' => "Mathematica",
'.eq' => "Logo",
'equal?' => "Scheme",
'equals' => "Java",
'equal' => "EmacsLisp CommonLisp Pike",
'equalp' => "CommonLisp",
'eqv' => "Perl6",
'deep_is_equal' => "Eiffel",
'isEqual' => "Objective-C",
],
],
'comparison' =>
[ { ALL => 1 },
'' =>
[
'< > <= >=' => "Ada Awk Io Beta Forth Maple Mathematica Logo B C C++ C# YCP E Matlab Scilab Java Pascal Rebol Smalltalk VisualBasic Scheme Pike Perl Perl6 merd Tcl Haskell Ruby SML OCaml F# PHP Eiffel JavaScript CoffeeScript EmacsLisp CommonLisp Dylan Lua Awk Modula-3 Python Pliant XPath ClassicREXX SQL92 Yorick Vimscript Go",
'< > =< >=' => "Mercury Oz",
"< > '> '<" => "MUMPS",
'<< >> <<= >>= (deep comparison)' => "ClassicREXX",
'@< / @=< / @> / @>=' => "Prolog",
'lt gt le ge' => "Perl Perl6 PostScript",
'-lt -gt -le -ge' => "BourneShell FishShell MSH",
'.LT. .GT. .LE. .GE.' => "Fortran",
'u< u> u<= u>=' => "Forth",
'f< f>' => "Forth",
],
'returns 3 values (i.e. inferior, equal or superior)' =>
[ { MLANG => 'B C C++ C# Ada Io Logo CommonLisp Awk Modula-3 Lua XSLT Rebol PostScript ClassicREXX Matlab' },
'a <=> b' => "Ruby Perl Perl6 merd",
'cmp' => "Perl Perl6 Python",
'compare' => "OCaml Forth F# Haskell Prolog Mercury Pliant Smalltalk",
'strcmp' => "PHP C",
'three_way_comparison' => "Eiffel",
'string compare' => "Tcl",
'compareTo' => 'Java',
'strings.Compare()' => 'Go',
],
'returns 4 values (i.e. inferior, equal, superior or not comparable)' =>
[ { KIND => 'rare' },
'compare' => "Pliant",
'compareTo' => 'E',
],
'min / max (binary or more)' =>
[ { MLANG => 'Ruby B C C# Awk XSLT Tcl Go' },
'min / max' => "Io C++ Java Forth PHP5 Tcl8.5 Rebol Maple Lua Beta Prolog Pike Matlab Scilab Python Smalltalk E Eiffel merd CommonLisp Scheme OCaml F# Haskell Dylan Pliant SQL92 Yorick",
'min minstr / max maxstr (in List::Util)' => "Perl",
'Min / Max' => "Oz Mathematica",
'MIN / MAX' => "Modula-3 ClassicREXX",
'measure-object -min / measure-object -max' => "MSH",
'fmin / fmax' => "Forth",
"Integer'min / Integer'max" => "Ada",
],
],
'runtime evaluation' =>
[ { KIND => 'dynamic', MLANG => "XSLT" },
'eval' => "Perl Perl6 Ruby Python BourneShell FishShell Scheme EmacsLisp Tcl Matlab PHP JavaScript CommonLisp YCP",
"CoffeeScript.eval (just 'eval' evaluates JavaScript)" => "CoffeeScript",
'exec' => "Python",
'evstr / execstr' => "Scilab",
'dostring' => "Lua",
'doString' => "Io",
'evaluate' => "Forth",
'Compiler evaluate:' => "Smalltalk",
'runtime_compile / compile + execute' => "Pliant",
'Compiler.evalExpression or Compiler.parseOzVirtualString' => "Oz",
'compile_string' => "Pike",
'interpret' => "ClassicREXX",
'ToExpression' => "Mathematica",
'run' => "Logo",
'XECUTE' => "MUMPS",
'do / reduce / compose / load' => "Rebol",
'[...]' => "Tcl",
'=.. (Univ operator)' => "Prolog",
],
'manual memory allocation' =>
[ { ALL => 1, KIND => 'rare' },
'allocation' =>
[
'malloc' => "C",
'allocate throw' => "Forth",
'new' => "Ada",
],
'deallocation' =>
[
'free' => "C",
'free throw' => "Forth",
],
],
'force garbage collection' =>
[ { MLANG => 'Ada B C C++ Forth Tcl CommonLisp Mathematica Pascal XSLT ClassicREXX MUMPS Matlab FishShell', },
'doGC' => "Beta",
'GC.start' => "Ruby",
'gc' => "Logo Pike Maple",
'System.gc()' => "Java",
'System.gcDo' => "Oz",
'System.GC.Collect()' => "C# F#",
'gc.collect()' => "Python",
'gc_collect_cycles (starting with PHP 5.3)' => 'PHP5',
'full_collect' => "Eiffel",
'garbage_collect' => "Mercury Prolog",
'collectgarbage' => "Lua",
'Collector collect' => "Io",
'VM.garbageCollect()' => "JavaScript",
'Gc.full_major()' => "OCaml",
'Smalltalk garbageCollect' => "Smalltalk",
'System.Mem.performGC' => 'Haskell',
'incremental garbage collection => not needed' => "Perl Perl6",
'recycle' => "Rebol",
'interp.gc()' => 'E',
'(ext:gc)' => "CommonLisp",
'runtime.GC()' => "Go",
],
],
'Functions' => [
'function call' =>
[ { ALL => 1 },
'' =>
[
'f(a,b,...)' => "Awk B C C++ C# Io CSS Maple Java YCP Matlab Erlang Pike Perl Perl6 Mercury merd Eiffel Python Ruby Pascal E PHP JavaScript CoffeeScript Dylan Lua Ada Awk Modula-3 XPath Prolog Yorick Go",
'f a b ...' => "SML Haskell Logo F# OCaml Rebol Matlab Tcl Pliant BourneShell FishShell MSH",
'f(a,b,...f) or f[a,b,...] depending on the version' => "BCPL",
'(f a b ...) (apply f l) ' => "Scheme EmacsLisp CommonLisp",
'(funcall f a b ...)' => "EmacsLisp CommonLisp",
'{f a b}' => "Oz",
'[apply f a b]' => "Tcl8.5",
'f[a,b,...]' => "Mathematica",
'f[a,b,...] or f.call(a,b,...)' => "Ruby",
'&$f(a,b,...) or $f->(a,b,...)' => "Perl",
'$f.(a,b,...)' => "Perl6",
'f a, b, ...' => "Perl CoffeeScript",
'f, a, b, ... (procedure call)' => "Yorick",
'v = f(a, b, ...) or call f a, b, ...' => "ClassicREXX",
'a b ... f' => "PostScript Forth",
# 'a f' => 'Smalltalk',
# 'a f: b g: ... (the function is "f: g:")' => "Smalltalk",
"(a,b,...)->&f or (a,b,...)->f" => "Beta",
'f:a (in Pliant, special sugar for only one parameter)' => 'FL',
'f@a (only for one parameter)' => "Mathematica",
'a // f (only for one parameter)' => "Mathematica",
'a ~ f ~ b (only for two parameters)' => "Mathematica",
'.. [ f, A, B, ...]' => "Prolog",
pre('<xsl:call-template name="f">
<xsl:with-param name="a" select=a/>
<xsl:with-param name="b" select=b/>
</xsl:call-template>') => "XSLT",
],
'with no parameter' =>
[
'f' => "Ada Eiffel Io Pascal Forth PostScript Logo Matlab Rebol Ruby Perl MSH Perl6 Mercury Haskell Tcl Pliant BourneShell Prolog Yorick", # Haskell egs: monads
'f()' => "Awk PHP Pike Maple Erlang Python C C++ C# YCP Java E Lua Perl JavaScript CoffeeScript merd OCaml F# SML Go",
'(f)' => "Scheme EmacsLisp CommonLisp",
'(funcall f)' => "EmacsLisp CommonLisp",
'{f}' => "Oz",
'f[]' => "Mathematica",
'f[] or f.call' => "Ruby",
'&$f or $f->()' => "Perl",
'$f.()' => "Perl6",
'v = f()' => "ClassicREXX",
'call f' => "ClassicREXX Fortran",
'f value (f is a block)' => "Smalltalk",
'<xsl:call-template name="f">/' => "XSLT",
],
],
'<a href="http://www.haskell.org/hawiki/PartialApplication">partial application</a> (in the examples below, a normal call is "f(a,b)")' =>
[ { KIND => 'functional', ALL => 1, MLANG => "Smalltalk Io Maple Mathematica CommonLisp Scheme Erlang Matlab" },
'give the first argument' =>
[
'f a' => "SML Haskell OCaml F#",
'f(a)' => "Mercury",
'f(a,)' => "merd",
'&f.assuming(var_name => a)' => "Perl6",
'functools.partial(f, a) (Python >= 2.5)' => "Python",
'interp alias {} f_a {} f a' => "Tcl",
],
'give the second argument' =>
[ { MLANG => 'SML Haskell OCaml F#' },
'f(,b)' => "merd",
'&f.assuming(b => b)' => "Perl6",
'flip f b (it does not scale to 3rd argument)' => "Haskell",
],
'give the first argument to operator ">"' =>
[
'(a >)' => "Haskell merd",
'(>) a' => "OCaml F#",
],
'give the second argument to operator ">"' =>
[ { MLANG => "OCaml F#" },
'(> a)' => "Haskell merd",
],
],
'function definition' =>
[
'' =>
[
'sub f { ... }' => "Perl Perl6",
'sub f($para1, $para2, ...) { ... }' => "Perl6",
'def f(para1, para2, ...): ...' => "Python",
'def f(para1, para2, ...) ... end' => "Ruby",
'def f(para1, para2, ...) ... { ... }' => "E",
'f para1 para2 = ...' => "Haskell",
'let f para1 para2 = ...' => "OCaml F#",
'f(para1, para2, ...) = valof $( ... $)' => "BCPL",
'f(para1, para2, ...) = ...' => "merd",
'f[para1_, para2_, ...] := ... para1 ...' => "Mathematica",
'f ... or f: para1 ...' => "Smalltalk",
'f: func [para1 para2 ...] ...' => "Rebol",
'/f { ... } def' => "PostScript",
'f := (para1, para2, ...) -> ...' => "Maple",
'f := method(para1, para2, ..., code)' => "Io",
'func f(a, b, c...) { ... }' => "Yorick",
'typ0 f(typ1 para1, typ2 para2, ...) { ... }' => "C C++ C# Pike YCP",
'function f(para1, para2) { ... }' => "Awk JavaScript PHP5",
'function f(para1, para2) ... code ... end' => "Lua",
'function f; ...; end' => "FishShell",
'function f { ... }' => "KornShell",
'function f { param(para1, [typ2]para2, ...) ... }' => "MSH",
'(define (f para1 para2) ...)' => "Scheme",
'(defun f (para1 para2) ...)' => "EmacsLisp CommonLisp",
'fun { F Para1 Para2 } ... end' => "Oz",
'fun f para1 para2 = ...' => 'SML',
'proc f {para1 para2} { ... }' => "Tcl",
pre('function retval = f(para1, para2)
retval = ...') => "Matlab Scilab",
pre(':- func f(typ1, typ2, ...) = typ0.
f(Para1, Para2, ...) = ...') => "Mercury",
pre('function f(para1 : type1; para2 : typ2; ...) return retval is
begin
...
end f;') => "Ada",
pre('function f para1 para2 -> retval
arg typ1 para1; arg typ2 para2; arg rettyp retval;
...') => "Pliant",
pre('function f(para1 : typ1, para2 : typ2, ...) : retval;
var retval : typ0;
begin
...
end') => 'Pascal',
pre('f (para1 : typ1; para2, para3 : typ2; ...) : rettyp is
do
...
end') => "Eiffel",
pre('<xsl:template name="f">
<xsl:param name="para1"/>
<xsl:param name="para2"/>
...
</xsl:template>') => "XSLT",
'Function f(para1, para2)
...
End Function' => "VisualBasic",
': f ... ;' => "Forth",
'f() { ... }' => 'BourneShell KornShell',
pre('f : procedure
...
return retval') => "ClassicREXX",
pre('to f :para1 :para2
...
end') => "Logo",
'func f(para1 typ1, para2 typ2, ...) (typ3, ...) { ... }' => "Go",
],
'procedures' =>
[
pre('procedure f(para1 : typ1; para2, para3 : typ2);
begin
...
end') => 'Pascal',
pre('f (para1 : typ1; para2, para3 : typ2; ...) is
do
...
end') => "Eiffel",
pre('procedure f(para1 : typ1; para2 : MODE type2; ...) is
begin
...
end f;
MODE ::= | OUT | IN OUT') => "Ada",
'void f(typ1 para1, typ2 para2, ...) { ... }' => "C C++ C# Pike",
'let f(para1, para2, ...) be $( ... $)' => "BCPL",
'proc { F Para1 Para2 } ... end' => "Oz",
'f := proc(para1, para2, ...) ... end proc' => "Maple",
'Sub f(para1, para2)
...
End Sub' => "VisualBasic",
pre('function f(para1, para2)
...') => "Matlab Scilab",
pre('f : procedure
...
return') => "ClassicREXX",
'func f(para1 typ1, para2 typ2, ...) { ... }' => "Go",
],
'variable number of arguments' =>
[
'one can use overloading on different number of arguments' => "C++ Java",
'sub f { ... @_ }' => 'Perl',
'sub f; ... $argv; end' => 'FishShell',
'f() { ... $@ }' => "BourneShell",
'f := ... ## &' => "Mathematica",
'f[params___] := ... params ...' => "Mathematica",
pre('function f(varargin)
for i=1:nargin
...(varargin{i})
end') => 'Matlab',
pre('function f(varargin)
for e=varargin
...(e)
end') => 'Scilab',
'(args...) -> ...' => 'CoffeeScript',
'(lambda x ...) or (lambda (x . y) ...)' => 'Scheme',
'f(args ...typ0) (only final parameter may be variadic and accepts ' .
'zero or more arguments)' => "Go",
],
'predicates' =>
[
'f(Para1, Para2, ....) :- ... .' => "Prolog",
],
],
'anonymous function' =>
[ { KIND => 'has_lambda' },
'sub { my ($a, $b) = @_; ... }' => "Perl",
'{ my ($a, $b) = @_; ... } (when callee has special "&" prototype)' => "Perl",
'{ ... } (arguments are in the stack' => "PostScript",
'[ ... ]' => "Logo",
'{ param(para1, [typ2]para2, ...) ... }' => "MSH",
"{|a, b| ... } (this is a block, not precisely a function, but it's alike)" => "Ruby",
'[:a :b| ... ]' => 'Smalltalk',
'[list {a b} {...}]' => "Tcl8.5",
'lambda a, b: ...' => "Python",
'lambda(typ1 para1, typ2, para2, ...) { ... };' => "Pike",
'(a, b) => ...' => "C#3 CoffeeScript",
"(a, b) -> ..." => "Maple CoffeeScript",
'a, b -> ...' => "merd",
'-> $a, $b { ... }' => "Perl6",
'\a b -> ...' => "Haskell",
':noname ...' => "Forth",
'fn (a, b) => ...' => "SML",
'fun a b -> ...' => "OCaml F#",
'(func(A, B) = C :- ...)' => "Mercury",
'function(a, b) { ... }' => "JavaScript PHP5",
'function(a, b) use (&$v1, $v2) { ... } (manual declaration of local variables wanted in the closure)' => "PHP5",
'function(a, b) ... end' => "Lua",
'Function[{a, b}, ....] (see also: #1 + #2 &)' => "Mathematica",
'fun(a, b) -> ... end' => "Erlang",
'fun {$ A B} ... end (also works for procedures: proc {$ A B} ... end)' => "Oz",
'func [a b ...] ...' => "Rebol",
'def _(para1, para2, ...) ... { ... }' => "E",
'proc {|a, b| ...}' => "Ruby",
'lambda {|a, b| ...}' => "Ruby",
'(lambda (a b) ...)', "Scheme EmacsLisp CommonLisp",
"inline('...x...y...') (x, y, z are the parameters)" => "Matlab",
'method(a, b, ...)' => "Io",
'method(a, b) ... end method (method is optional)' => "Dylan",
"create_function('$a,$b','...')" => "PHP",
'delegate(ta a, tb b) { ... }' => "C#2",
'[](ta a, tb b) { ... }' => "C++-0x",
'[](ta a, tb b) -> typ { ... }' => "C++-0x",
'func(para1 typ1, ...) (typ2, ...) { ... }' => "Go",
],
'function return value' =>
[ { MLANG => 'Prolog PostScript' },
'breaks the control flow' => ($::return_a_value =
[
q(return (in Lua, "return xxx" can only appear before a block end. in Matlab, only in inline('...'))) => "Awk Io B BCPL CommonLisp C Maple C++ C# ClassicREXX FishShell Java E Pike YCP Perl Perl6 Ruby Rebol Python Tcl Ada PHP Pliant JavaScript CoffeeScript BourneShell Yorick Lua Matlab Go Vimscript",
'Return' => "VisualBasic Mathematica",
'RETURN' => "Modula-3",
'resultis ("return" is used when there is no value to return)' => "BCPL",
'return-from xxx' => "CommonLisp",
'^' => "Smalltalk",
'Exit Function / Exit Sub' => "VisualBasic",
'exit' => "Forth",
'output' => "Logo",
]),
'function body is the result' =>
[
'no syntax needed (in Matlab, only for anonymous function)' => "Maple Io Mathematica Haskell OCaml F# Erlang SML EmacsLisp Tcl Rebol CommonLisp Scheme Perl Perl6 Ruby Dylan Oz Matlab CoffeeScript",
],
'setting the result' =>
[
'Result := val' => "Eiffel",
'<function name> = val' => "VisualBasic",
'<function name> := val' => "Pascal",
'<retvar name> = val;' => "Matlab Ada",
],
],
'function called when a function is not defined (in dynamic languages)' =>
[ { KIND => 'dynamic', MLANG => 'Logo Oz Forth Rebol ClassicREXX Matlab', }, # in Oz: the function call is postponed until the function gets defined. So the current thread will block, waiting for another thread to define the function. (mechanism of dataflow variables)
'AUTOLOAD' => "Perl",
'AUTOSCALAR, AUTOMETH, AUTOLOAD...' => "Perl6",
'__autoload' => 'PHP5',
'__getattr__' => "Python",
'method_missing' => "Ruby",
'doesNotUnderstand' => "Smalltalk",
'__noSuchMethod__ (firefox)' => "JavaScript CoffeeScript",
'unknown' => "Tcl",
'no-applicable-method' => "CommonLisp",
'doesNotRecognizeSelector' => "Objective-C",
'TryInvokeMember (C#4, only for "dynamic" objects)' => "C#",
'match [name, args] { ... }' => "E",
'the predicate fail' => "Prolog",
'forward' => "Io",
],
'runtime inspecting the caller information' =>
[ { KIND => 'dynamic', MLANG => 'E Forth CommonLisp Logo' },
'caller' => "Perl Perl6 Ruby",
'call' => "Io",
'inspect.stack()[1]' => "Python",
'backtrace' => "Pike",
'debug_backtrace' => "PHP5",
"trace 'I'" => "ClassicREXX",
"evalin('caller', ...)" => "Matlab",
'current_predicate' => "Prolog",
'thisContext sender' => "Smalltalk",
'where(2)' => "Maple",
'info level' => "Tcl",
'runtime.Caller(0)' => "Go",
],
'function composition' =>
[ { KIND => 'functional', MLANG => 'OCaml Io CommonLisp Smalltalk Matlab Logo', },
'.' => "Haskell",
'~' => "merd",
'o' => "SML",
'@' => "Maple",
'compose' => 'Dylan',
'Composition' => "Mathematica",
'<<' => "F#",
'>>' => "F#",
],
'identity function' =>
[ { KIND => 'functional', MLANG => 'OCaml F# Erlang Logo', },
'id' => "Haskell",
'identity' => "CommonLisp",
'Identity' => "Mathematica",
'yourself' => "Smalltalk",
],
],
'Control Flow' => [
{ MLANG => 'Haskell XSLT' },
'sequence' =>
[ { MLANG => "Forth PostScript Oz" },
',' => "C C++ Perl Matlab Scilab Pike JavaScript Prolog Go",
'.' => "Smalltalk",
';' => "Awk Maple Mathematica Beta Io PL/I B C C++ C# Java Matlab YCP Pike Pascal Python Ruby Perl Perl6 OCaml F# SML merd Tcl E PHP JavaScript Ada BourneShell FishShell Haskell Modula-3 Pliant GNU-sed Go",
':' => "Maple",
'nothing, optionally ;' => "Lua ClassicREXX",
'space' => "Eiffel Rebol",
'end-of-line' => "Awk Ruby F# Io Python Lua merd Basic Tcl E Matlab Fortran Assembler JavaScript CoffeeScript BourneShell FishShell Haskell Pliant GNU-sed",
'(begin ...)' => "Scheme",
'(progn ...) (prog1 ...) (prog2 ...) ' => "EmacsLisp CommonLisp",
'>>' => "Haskell",
],
'if_then' =>
[ { MLANG => "SML Prolog Haskell" },
'if c then ...' => "OCaml F# Tcl merd Pascal CoffeeScript",
'if c then ... end' => "Ruby Eiffel Lua Oz",
'if c then ... end if' => "Ada Maple",
'if c then ... fi' => "Maple",
'if c; then ... fi' => "BourneShell",
'if (c) then ... end' => "Dylan",
'if c do ...' => "BCPL",
'IF c THEN ... END' => "Modula-2 Modula-3",
'if (c) ...' => "Awk B C C# C++ Java Pike PHP JavaScript YCP",
'if c: ...' => "Python",
'if c ...' => "Pliant Rebol Tcl",
'if (c): ... endif' => "PHP",
'if c {...}' => "Perl6 Go",
'if c [...]' => "Logo",
'if (c) {...}' => "Perl E Yorick",
'IF c ...' => "MUMPS",
'c -> ...' => 'FL',
'c ... if' => "PostScript",
'... if c' => "Perl Ruby",
'c if b1 then' => "Forth",
'(if c ...)' => "CommonLisp Scheme",
'(when c ...)' => "EmacsLisp",
'c and ...' => "Perl Ruby",
'if(c, ...)' => "Io",
'If[c, ...]' => "Mathematica",
'if(c) then(...)' => "Io",
'c ifTrue(...)' => "Io",
'c ifTrue: ...' => "Smalltalk",
'<xsl:if test="c">...</xsl:if>' => "XSLT",
'if c ... endif' => 'Vimscript',
'If c Then ...' => "VisualBasic",
pre('If c
...