-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathJUnitHttpProxy.http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FScala_%28programming_language%29.tmp
1793 lines (1763 loc) · 286 KB
/
JUnitHttpProxy.http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FScala_%28programming_language%29.tmp
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
<!DOCTYPE html>
<html lang="en" dir="ltr" class="client-nojs">
<head>
<meta charset="UTF-8" /><title>Scala (programming language) - Wikipedia, the free encyclopedia</title>
<meta name="generator" content="MediaWiki 1.22wmf21" />
<link rel="alternate" type="application/x-wiki" title="Edit this page" href="/w/index.php?title=Scala_(programming_language)&action=edit" />
<link rel="edit" title="Edit this page" href="/w/index.php?title=Scala_(programming_language)&action=edit" />
<link rel="shortcut icon" href="//bits.wikimedia.org/favicon/wikipedia.ico" />
<link rel="search" type="application/opensearchdescription+xml" href="/w/opensearch_desc.php" title="Wikipedia (en)" />
<link rel="EditURI" type="application/rsd+xml" href="//en.wikipedia.org/w/api.php?action=rsd" />
<link rel="copyright" href="//creativecommons.org/licenses/by-sa/3.0/" />
<link rel="alternate" type="application/atom+xml" title="Wikipedia Atom feed" href="/w/index.php?title=Special:RecentChanges&feed=atom" />
<link rel="canonical" href="http://en.wikipedia.org/wiki/Scala_(programming_language)" />
<link rel="stylesheet" href="//bits.wikimedia.org/en.wikipedia.org/load.php?debug=false&lang=en&modules=ext.gadget.DRN-wizard%2CReferenceTooltips%2Ccharinsert%2Cteahouse%7Cext.geshi.local%7Cext.rtlcite%2Cwikihiero%7Cext.uls.nojs%7Cext.visualEditor.viewPageTarget.noscript%7Cmediawiki.legacy.commonPrint%2Cshared%7Cmw.PopUpMediaTransform%7Cskins.vector&only=styles&skin=vector&*" />
<meta name="ResourceLoaderDynamicStyles" content="" />
<link rel="stylesheet" href="//bits.wikimedia.org/en.wikipedia.org/load.php?debug=false&lang=en&modules=site&only=styles&skin=vector&*" />
<style>a:lang(ar),a:lang(ckb),a:lang(kk-arab),a:lang(mzn),a:lang(ps),a:lang(ur){text-decoration:none}
/* cache key: enwiki:resourceloader:filter:minify-css:7:0de201fdea5d684523607ed88007b127 */</style>
<script src="//bits.wikimedia.org/en.wikipedia.org/load.php?debug=false&lang=en&modules=startup&only=scripts&skin=vector&*"></script>
<script>if(window.mw){
mw.config.set({"wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"Scala_(programming_language)","wgTitle":"Scala (programming language)","wgCurRevisionId":577835793,"wgRevisionId":577835793,"wgArticleId":3254510,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["Articles with Dutch-language external links","Articles needing cleanup from June 2013","Articles needing link rot cleanup from June 2013","All articles needing link rot cleanup","Articles covered by WikiProject Wikify from June 2013","All articles covered by WikiProject Wikify","Articles needing additional references from June 2013","All articles needing additional references","All Wikipedia articles needing clarification","Wikipedia articles needing clarification from September 2013",".NET programming languages","Articles with example code","Concurrent programming languages","Java platform","Java programming language family","JVM programming languages","Functional languages","Object-oriented programming languages","Scala programming language","Scripting languages","Statically typed programming languages","2003 introductions","Programming languages created in 2003","Programming languages created in the 2000s"],"wgBreakFrames":false,"wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy","wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgMonthNamesShort":["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"wgRelevantPageName":"Scala_(programming_language)","wgIsProbablyEditable":true,"wgRestrictionEdit":[],"wgRestrictionMove":[],"wgWikiEditorEnabledModules":{"toolbar":true,"dialogs":true,"hidesig":true,"templateEditor":false,"templates":false,"preview":false,"previewDialog":false,"publish":false,"toc":false},"wgArticleFeedbackv5Permissions":{"aft-reader":true,"aft-member":false,"aft-editor":false,"aft-monitor":false,"aft-administrator":false,"aft-oversighter":false,"aft-noone":false},"wgVisualEditor":{"isPageWatched":false,"magnifyClipIconURL":"//bits.wikimedia.org/static-1.22wmf21/skins/common/images/magnify-clip.png","pageLanguageCode":"en","pageLanguageDir":"ltr"},"wikilove-recipient":"","wikilove-anon":0,"wgGuidedTourHelpGuiderUrl":"Help:Guided tours/guider","wgULSAcceptLanguageList":["en","en-gb"],"wgFlaggedRevsParams":{"tags":{"status":{"levels":1,"quality":2,"pristine":3}}},"wgStableRevisionId":null,"wgCategoryTreePageCategoryOptions":"{\"mode\":0,\"hideprefix\":20,\"showcount\":true,\"namespaces\":false}","Geo":{"city":"","country":""},"wgNoticeProject":"wikipedia","aftv5Article":{"id":3254510,"title":"Scala (programming language)","namespace":0,"categories":[".NET programming languages","2003 introductions","All Wikipedia articles needing clarification","All articles covered by WikiProject Wikify","All articles needing additional references","All articles needing link rot cleanup","Articles covered by WikiProject Wikify from June 2013","Articles needing additional references from June 2013","Articles needing cleanup from June 2013","Articles needing link rot cleanup from June 2013","Articles with Dutch-language external links","Articles with example code","Concurrent programming languages","Functional languages","JVM programming languages","Java platform","Java programming language family","Object-oriented programming languages","Programming languages created in 2003","Programming languages created in the 2000s","Scala programming language","Scripting languages","Statically typed programming languages","Wikipedia articles needing clarification from September 2013"],"permissionLevel":"aft-reader"},"wgWikibaseItemId":"Q460584"});
}</script><script>if(window.mw){
mw.loader.implement("user.options",function(){mw.user.options.set({"ccmeonemails":0,"cols":80,"date":"default","diffonly":0,"disablemail":0,"disablesuggest":0,"editfont":"default","editondblclick":0,"editsection":1,"editsectiononrightclick":0,"enotifminoredits":0,"enotifrevealaddr":0,"enotifusertalkpages":1,"enotifwatchlistpages":0,"extendwatchlist":0,"fancysig":0,"forceeditsummary":0,"gender":"unknown","hideminor":0,"hidepatrolled":0,"imagesize":2,"justify":0,"math":0,"minordefault":0,"newpageshidepatrolled":0,"nocache":0,"noconvertlink":0,"norollbackdiff":0,"numberheadings":0,"previewonfirst":0,"previewontop":1,"rcdays":7,"rclimit":50,"rememberpassword":0,"rows":25,"searchlimit":20,"showhiddencats":false,"shownumberswatching":1,"showtoc":1,"showtoolbar":1,"skin":"vector","stubthreshold":0,"thumbsize":4,"underline":2,"uselivepreview":0,"usenewrc":0,"vector-simplesearch":1,"watchcreations":1,"watchdefault":0,"watchdeletion":0,"watchlistdays":3,"watchlisthideanons":0,"watchlisthidebots"
:0,"watchlisthideliu":0,"watchlisthideminor":0,"watchlisthideown":0,"watchlisthidepatrolled":0,"watchmoves":0,"wllimit":250,"useeditwarning":1,"prefershttps":1,"flaggedrevssimpleui":1,"flaggedrevsstable":0,"flaggedrevseditdiffs":true,"flaggedrevsviewdiffs":false,"usebetatoolbar":1,"usebetatoolbar-cgd":1,"aftv5-last-filter":null,"visualeditor-enable":0,"visualeditor-enable-experimental":0,"visualeditor-betatempdisable":0,"wikilove-enabled":1,"echo-subscriptions-web-page-review":true,"echo-subscriptions-email-page-review":false,"ep_showtoplink":false,"ep_bulkdelorgs":false,"ep_bulkdelcourses":true,"ep_showdyk":true,"echo-notify-show-link":true,"echo-show-alert":true,"echo-email-frequency":0,"echo-email-format":"html","echo-subscriptions-email-system":true,"echo-subscriptions-web-system":true,"echo-subscriptions-email-other":false,"echo-subscriptions-web-other":true,"echo-subscriptions-email-edit-user-talk":false,"echo-subscriptions-web-edit-user-talk":true,
"echo-subscriptions-email-reverted":false,"echo-subscriptions-web-reverted":true,"echo-subscriptions-email-article-linked":false,"echo-subscriptions-web-article-linked":false,"echo-subscriptions-email-mention":false,"echo-subscriptions-web-mention":true,"echo-subscriptions-web-edit-thank":true,"echo-subscriptions-email-edit-thank":false,"gettingstarted-task-toolbar-show-intro":true,"uls-preferences":"","language":"en","variant-gan":"gan","variant-iu":"iu","variant-kk":"kk","variant-ku":"ku","variant-shi":"shi","variant-sr":"sr","variant-tg":"tg","variant-uz":"uz","variant-zh":"zh","searchNs0":true,"searchNs1":false,"searchNs2":false,"searchNs3":false,"searchNs4":false,"searchNs5":false,"searchNs6":false,"searchNs7":false,"searchNs8":false,"searchNs9":false,"searchNs10":false,"searchNs11":false,"searchNs12":false,"searchNs13":false,"searchNs14":false,"searchNs15":false,"searchNs100":false,"searchNs101":false,"searchNs108":false,"searchNs109":false,"searchNs446":false,"searchNs447":false
,"searchNs710":false,"searchNs711":false,"searchNs828":false,"searchNs829":false,"gadget-teahouse":1,"gadget-ReferenceTooltips":1,"gadget-DRN-wizard":1,"gadget-charinsert":1,"gadget-mySandbox":1,"variant":"en"});},{},{});mw.loader.implement("user.tokens",function(){mw.user.tokens.set({"editToken":"+\\","patrolToken":false,"watchToken":false});},{},{});
/* cache key: enwiki:resourceloader:filter:minify-js:7:f518b864f4c01710d57ac85913b8c7f0 */
}</script>
<script>if(window.mw){
mw.loader.load(["mediawiki.page.startup","mediawiki.legacy.wikibits","mediawiki.legacy.ajax","ext.centralauth.centralautologin","ext.visualEditor.viewPageTarget.init","ext.wikimediaShopLink.core","ext.uls.init","ext.uls.interface","wikibase.client.init","ext.centralNotice.bannerController","skins.vector.js"]);
}</script>
<style type="text/css">/*<![CDATA[*/
.source-scala {line-height: normal;}
.source-scala li, .source-scala pre {
line-height: normal; border: 0px none white;
}
/**
* GeSHi Dynamically Generated Stylesheet
* --------------------------------------
* Dynamically generated stylesheet for scala
* CSS class: source-scala, CSS id:
* GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
* (http://qbnz.com/highlighter/ and http://geshi.org/)
* --------------------------------------
*/
.scala.source-scala .de1, .scala.source-scala .de2 {font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;font-family: monospace, monospace;}
.scala.source-scala {font-family:monospace;}
.scala.source-scala .imp {font-weight: bold; color: red;}
.scala.source-scala li, .scala.source-scala .li1 {font-weight: normal; vertical-align:top;}
.scala.source-scala .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}
.scala.source-scala .li2 {font-weight: bold; vertical-align:top;}
.scala.source-scala .kw1 {color: #0000ff; font-weight: bold;}
.scala.source-scala .kw2 {color: #9999cc; font-weight: bold;}
.scala.source-scala .co1 {color: #008000; font-style: italic;}
.scala.source-scala .co2 {color: #CC66FF;}
.scala.source-scala .coMULTI {color: #00ff00; font-style: italic;}
.scala.source-scala .es0 {color: #6666ff; font-weight: bold;}
.scala.source-scala .es1 {color: #6666ff; font-weight: bold;}
.scala.source-scala .es2 {color: #5555ff; font-weight: bold;}
.scala.source-scala .es3 {color: #4444ff; font-weight: bold;}
.scala.source-scala .es4 {color: #3333ff; font-weight: bold;}
.scala.source-scala .br0 {color: #F78811;}
.scala.source-scala .sy0 {color: #000080;}
.scala.source-scala .st0 {color: #6666FF;}
.scala.source-scala .nu0 {color: #F78811;}
.scala.source-scala .me1 {color: #000000;}
.scala.source-scala .me2 {color: #000000;}
.scala.source-scala .ln-xtra, .scala.source-scala li.ln-xtra, .scala.source-scala div.ln-xtra {background-color: #ffc;}
.scala.source-scala span.xtra { display:block; }
/*]]>*/
</style><style type="text/css">/*<![CDATA[*/
.source-java {line-height: normal;}
.source-java li, .source-java pre {
line-height: normal; border: 0px none white;
}
/**
* GeSHi Dynamically Generated Stylesheet
* --------------------------------------
* Dynamically generated stylesheet for java
* CSS class: source-java, CSS id:
* GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
* (http://qbnz.com/highlighter/ and http://geshi.org/)
* --------------------------------------
*/
.java.source-java .de1, .java.source-java .de2 {font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;font-family: monospace, monospace;}
.java.source-java {font-family:monospace;}
.java.source-java .imp {font-weight: bold; color: red;}
.java.source-java li, .java.source-java .li1 {font-weight: normal; vertical-align:top;}
.java.source-java .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}
.java.source-java .li2 {font-weight: bold; vertical-align:top;}
.java.source-java .kw1 {color: #000000; font-weight: bold;}
.java.source-java .kw2 {color: #000066; font-weight: bold;}
.java.source-java .kw3 {color: #003399;}
.java.source-java .kw4 {color: #000066; font-weight: bold;}
.java.source-java .co1 {color: #666666; font-style: italic;}
.java.source-java .co2 {color: #006699;}
.java.source-java .co3 {color: #008000; font-style: italic; font-weight: bold;}
.java.source-java .coMULTI {color: #666666; font-style: italic;}
.java.source-java .es0 {color: #000099; font-weight: bold;}
.java.source-java .br0 {color: #009900;}
.java.source-java .sy0 {color: #339933;}
.java.source-java .st0 {color: #0000ff;}
.java.source-java .nu0 {color: #cc66cc;}
.java.source-java .me1 {color: #006633;}
.java.source-java .me2 {color: #006633;}
.java.source-java .ln-xtra, .java.source-java li.ln-xtra, .java.source-java div.ln-xtra {background-color: #ffc;}
.java.source-java span.xtra { display:block; }
/*]]>*/
</style><script src="//bits.wikimedia.org/geoiplookup"></script><link rel="dns-prefetch" href="//meta.wikimedia.org" /><!--[if lt IE 7]><style type="text/css">body{behavior:url("/w/static-1.22wmf21/skins/vector/csshover.min.htc")}</style><![endif]--></head>
<body class="mediawiki ltr sitedir-ltr ns-0 ns-subject page-Scala_programming_language skin-vector action-view vector-animateLayout">
<div id="mw-page-base" class="noprint"></div>
<div id="mw-head-base" class="noprint"></div>
<div id="content" class="mw-body" role="main">
<a id="top"></a>
<div id="mw-js-message" style="display:none;"></div>
<div id="siteNotice"><!-- CentralNotice --></div>
<h1 id="firstHeading" class="firstHeading" lang="en"><span dir="auto">Scala (programming language)</span></h1>
<div id="bodyContent">
<div id="siteSub">From Wikipedia, the free encyclopedia</div>
<div id="contentSub"></div>
<div id="jump-to-nav" class="mw-jump">
Jump to: <a href="#mw-navigation">navigation</a>, <a href="#p-search">search</a>
</div>
<div id="mw-content-text" lang="en" dir="ltr" class="mw-content-ltr"><table class="metadata plainlinks ambox ambox-style ambox-cleanup-link_rot" role="presentation">
<tr>
<td class="mbox-image">
<div style="width:52px;"><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Text_document_with_red_question_mark.svg/40px-Text_document_with_red_question_mark.svg.png" width="40" height="40" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Text_document_with_red_question_mark.svg/60px-Text_document_with_red_question_mark.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Text_document_with_red_question_mark.svg/80px-Text_document_with_red_question_mark.svg.png 2x" /></div>
</td>
<td class="mbox-text"><span class="mbox-text-span">This article uses <a href="/wiki/Wikipedia:Bare_URLs" title="Wikipedia:Bare URLs">bare URLs</a> for <a href="/wiki/Wikipedia:Citing_sources" title="Wikipedia:Citing sources">citations</a>, which may be threatened by <a href="/wiki/Wikipedia:Link_rot" title="Wikipedia:Link rot">link rot</a>. <span class="hide-when-compact">Please consider adding <a href="/wiki/Wikipedia:Citing_sources#Citation_styles" title="Wikipedia:Citing sources">full citations</a> so that the article remains <a href="/wiki/Wikipedia:Verifiability" title="Wikipedia:Verifiability">verifiable</a>. <a href="/wiki/Wikipedia:Template_messages/Sources_of_articles#Examples" title="Wikipedia:Template messages/Sources of articles">Several templates</a> and the <a rel="nofollow" class="external text" href="//toolserver.org/%7Edispenser/cgi-bin/webreflinks.py?page=Scala_(programming_language)&citeweb=on&overwrite=simple&limit=200">Reflinks tool</a> are available to assist in formatting. (<a href="/wiki/Wikipedia:REFLINKS" title="Wikipedia:REFLINKS" class="mw-redirect">Reflinks documentation</a>)</span> <small><i>(June 2013)</i></small></span></td>
</tr>
</table>
<table class="infobox vevent" cellspacing="3" style="border-spacing:3px;width:22em;">
<caption class="summary">Scala</caption>
<tr>
<td colspan="2" style="text-align:center;"><a href="/wiki/File:Scala_logo.png" class="image"><img alt="Scala logo.png" src="//upload.wikimedia.org/wikipedia/en/thumb/8/85/Scala_logo.png/200px-Scala_logo.png" width="200" height="57" srcset="//upload.wikimedia.org/wikipedia/en/thumb/8/85/Scala_logo.png/300px-Scala_logo.png 1.5x, //upload.wikimedia.org/wikipedia/en/8/85/Scala_logo.png 2x" /></a></td>
</tr>
<tr>
<th scope="row" style="text-align:left;"><a href="/wiki/Programming_paradigm" title="Programming paradigm">Paradigm(s)</a></th>
<td><a href="/wiki/Multi-paradigm_programming_language" title="Multi-paradigm programming language" class="mw-redirect">Multi-paradigm</a>: <a href="/wiki/Functional_programming" title="Functional programming">functional</a>, <a href="/wiki/Object-oriented_programming" title="Object-oriented programming">object-oriented</a>, <a href="/wiki/Imperative_programming" title="Imperative programming">imperative</a>, <a href="/wiki/Concurrent_programming" title="Concurrent programming" class="mw-redirect">concurrent</a></td>
</tr>
<tr>
<th scope="row" style="text-align:left;">Appeared in</th>
<td>2003</td>
</tr>
<tr>
<th scope="row" style="text-align:left;">Designed by</th>
<td><a href="/wiki/Martin_Odersky" title="Martin Odersky">Martin Odersky</a></td>
</tr>
<tr>
<th scope="row" style="text-align:left;"><a href="/wiki/Software_developer" title="Software developer">Developer</a></th>
<td class="organiser">Programming Methods Laboratory of <a href="/wiki/%C3%89cole_Polytechnique_F%C3%A9d%C3%A9rale_de_Lausanne" title="École Polytechnique Fédérale de Lausanne">École Polytechnique Fédérale de Lausanne</a></td>
</tr>
<tr>
<th scope="row" style="text-align:left;"><a href="/wiki/Software_release_life_cycle" title="Software release life cycle">Stable release</a></th>
<td>2.10.2 (June 6, 2013<span style="display:none"> (<span class="bday dtstart published updated">2013-06-06</span>)</span><sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span>[</span>1<span>]</span></a></sup>)</td>
</tr>
<tr>
<th scope="row" style="text-align:left;"><a href="/wiki/Software_release_life_cycle" title="Software release life cycle">Preview release</a></th>
<td>2.11.0-M4 (June 11, 2013<span style="display:none"> (<span class="bday dtstart published updated">2013-06-11</span>)</span><sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span>[</span>2<span>]</span></a></sup>)</td>
</tr>
<tr>
<th scope="row" style="text-align:left;"><a href="/wiki/Type_system" title="Type system">Typing discipline</a></th>
<td><a href="/wiki/Static_typing" title="Static typing" class="mw-redirect">static</a>, <a href="/wiki/Strong_typing" title="Strong typing" class="mw-redirect">strong</a>, <a href="/wiki/Type_inference" title="Type inference">inferred</a>, <a href="/wiki/Structural_type_system" title="Structural type system">structural</a></td>
</tr>
<tr>
<th scope="row" style="text-align:left;">Influenced by</th>
<td><a href="/wiki/Eiffel_(programming_language)" title="Eiffel (programming language)">Eiffel</a>, <a href="/wiki/Erlang_(programming_language)" title="Erlang (programming language)">Erlang</a>, <a href="/wiki/Haskell_(programming_language)" title="Haskell (programming language)">Haskell</a>,<sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span>[</span>3<span>]</span></a></sup> <a href="/wiki/Java_(programming_language)" title="Java (programming language)">Java</a>, <a href="/wiki/Lisp_(programming_language)" title="Lisp (programming language)">Lisp</a>,<sup id="cite_ref-Scala_Macros_4-0" class="reference"><a href="#cite_note-Scala_Macros-4"><span>[</span>4<span>]</span></a></sup> <a href="/wiki/Pizza_(programming_language)" title="Pizza (programming language)">Pizza</a>,<sup id="cite_ref-overview_5-0" class="reference"><a href="#cite_note-overview-5"><span>[</span>5<span>]</span></a></sup> <a href="/wiki/Standard_ML" title="Standard ML">Standard ML</a>, <a href="/wiki/OCaml" title="OCaml">OCaml</a>, <a href="/wiki/Scheme_(programming_language)" title="Scheme (programming language)">Scheme</a>, <a href="/wiki/Smalltalk" title="Smalltalk">Smalltalk</a>, <a href="/wiki/Oz_(programming_language)" title="Oz (programming language)">Oz</a></td>
</tr>
<tr>
<th scope="row" style="text-align:left;">Influenced</th>
<td><a href="/wiki/Fantom_(programming_language)" title="Fantom (programming language)">Fantom</a>, <a href="/wiki/Ceylon_Project" title="Ceylon Project" class="mw-redirect">Ceylon</a>, <a href="/w/index.php?title=Kotlin_(programming_language)&action=edit&redlink=1" class="new" title="Kotlin (programming language) (page does not exist)">Kotlin</a></td>
</tr>
<tr>
<th scope="row" style="text-align:left;">Implementation language</th>
<td><a href="/wiki/Java_(programming_language)" title="Java (programming language)">Java</a></td>
</tr>
<tr>
<th scope="row" style="text-align:left;"><a href="/wiki/Computing_platform" title="Computing platform">Platform</a></th>
<td><a href="/wiki/JVM" title="JVM" class="mw-redirect">JVM</a>, <a href="/wiki/LLVM" title="LLVM">LLVM</a></td>
</tr>
<tr>
<th scope="row" style="text-align:left;"><a href="/wiki/Software_license" title="Software license">License</a></th>
<td><a href="/wiki/BSD_licenses" title="BSD licenses">BSD</a></td>
</tr>
<tr>
<th scope="row" style="text-align:left;">Usual <a href="/wiki/Filename_extension" title="Filename extension">filename extensions</a></th>
<td>.scala</td>
</tr>
<tr>
<th scope="row" style="text-align:left;">Website</th>
<td><span class="url"><a rel="nofollow" class="external text" href="http://www.scala-lang.org/">www.scala-lang.org</a></span></td>
</tr>
<tr>
<td colspan="2" class="hlist" style="text-align:center;">
<ul>
<li><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/d/df/Wikibooks-logo-en-noslogan.svg/16px-Wikibooks-logo-en-noslogan.svg.png" width="16" height="16" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/d/df/Wikibooks-logo-en-noslogan.svg/24px-Wikibooks-logo-en-noslogan.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/d/df/Wikibooks-logo-en-noslogan.svg/32px-Wikibooks-logo-en-noslogan.svg.png 2x" /> <a href="//en.wikibooks.org/wiki/Scala" class="extiw" title="wikibooks:Scala">Scala</a> at Wikibooks</li>
</ul>
</td>
</tr>
</table>
<p><b>Scala</b> (<span class="nowrap"><span title="Representation in the International Phonetic Alphabet (IPA)" class="IPA"><a href="/wiki/Help:IPA_for_English" title="Help:IPA for English">/</a></span><span class="IPA nopopups"><a href="/wiki/Help:IPA_for_English#Key" title="Help:IPA for English"><span title="/ˈ/ primary stress follows" style="border-bottom:1px dotted">ˈ</span></a></span><span class="IPA nopopups"><a href="/wiki/Help:IPA_for_English#Key" title="Help:IPA for English"><span title="'s' in 'sigh'" style="border-bottom:1px dotted">s</span></a></span><span class="IPA nopopups"><a href="/wiki/Help:IPA_for_English#Key" title="Help:IPA for English"><span title="'k' in 'kind'" style="border-bottom:1px dotted">k</span></a></span><span class="IPA nopopups"><a href="/wiki/Help:IPA_for_English#Key" title="Help:IPA for English"><span title="/ɑː/ 'a' in 'father'" style="border-bottom:1px dotted">ɑː</span></a></span><span class="IPA nopopups"><a href="/wiki/Help:IPA_for_English#Key" title="Help:IPA for English"><span title="'l' in 'lie'" style="border-bottom:1px dotted">l</span></a></span><span class="IPA nopopups"><a href="/wiki/Help:IPA_for_English#Key" title="Help:IPA for English"><span title="/ə/ 'a' in 'about'" style="border-bottom:1px dotted">ə</span></a></span><span title="Representation in the International Phonetic Alphabet (IPA)" class="IPA"><a href="/wiki/Help:IPA_for_English" title="Help:IPA for English">/</a></span></span> <span title="English pronunciation respelling" class="Unicode"><a href="/wiki/Wikipedia:Pronunciation_respelling_key" title="Wikipedia:Pronunciation respelling key"><i><b><span class="smallcaps"><span class="SMALLCAPS" style="FONT-VARIANT:SMALL-CAPS;"><span class="NOCAPS" style="TEXT-TRANSFORM:LOWERCASE;">SKAH</span></span></span></b>-lə</i></a></span>) is an <a href="/wiki/Multi-paradigm_programming_language" title="Multi-paradigm programming language" class="mw-redirect">object-functional</a> <a href="/wiki/Programming_language" title="Programming language">programming</a> and <a href="/wiki/Scripting_language" title="Scripting language">scripting language</a> for general <a href="/wiki/Software_application" title="Software application" class="mw-redirect">software applications</a>, <a href="/wiki/Static_typing" title="Static typing" class="mw-redirect">statically typed</a>, designed to concisely express solutions in an elegant,<sup id="cite_ref-6" class="reference"><a href="#cite_note-6"><span>[</span>6<span>]</span></a></sup> <a href="/wiki/Type-safe" title="Type-safe" class="mw-redirect">type-safe</a> and lightweight (low ceremonial) manner. Scala has full support for <a href="/wiki/Functional_programming" title="Functional programming">functional programming</a> (including <a href="/wiki/Currying" title="Currying">currying</a>, <a href="/wiki/Pattern_matching" title="Pattern matching">pattern matching</a>, <a href="/wiki/Algebraic_data_types" title="Algebraic data types" class="mw-redirect">algebraic data types</a>, <a href="/wiki/Lazy_evaluation" title="Lazy evaluation">lazy evaluation</a>, <a href="/wiki/Tail_recursion" title="Tail recursion" class="mw-redirect">tail recursion</a>, <a href="/wiki/Immutable_object" title="Immutable object">immutability</a>, etc.). It cleans up what are often considered poor design decisions in Java (such as <a href="/wiki/Type_erasure" title="Type erasure">type erasure</a>, <a href="/wiki/Checked_exception" title="Checked exception" class="mw-redirect">checked exceptions</a>, the non-<a href="/wiki/Type_system#Unified_Type_System" title="Type system">unified type system</a>) and adds a number of other features designed to allow cleaner, more concise and more expressive code to be written.<sup id="cite_ref-overview_5-1" class="reference"><a href="#cite_note-overview-5"><span>[</span>5<span>]</span></a></sup></p>
<p>It is intended to be compiled to <a href="/wiki/Java_bytecode" title="Java bytecode">Java bytecode</a>, so the resulting executable runs on the <a href="/wiki/JVM" title="JVM" class="mw-redirect">JVM</a>, and Java libraries can be used directly in Scala code and vice-versa. Like Java, Scala is <a href="/wiki/Static_typing" title="Static typing" class="mw-redirect">statically typed</a> and <a href="/wiki/Object-oriented_programming" title="Object-oriented programming">object-oriented</a>, uses a curly-brace syntax reminiscent of <a href="/wiki/C_(programming_language)" title="C (programming language)">C</a>. Unlike Java, Scala has many features of <a href="/wiki/Functional_programming" title="Functional programming">functional programming</a> languages like <a href="/wiki/Scheme_(programming_language)" title="Scheme (programming language)">Scheme</a>, <a href="/wiki/Standard_ML" title="Standard ML">Standard ML</a> and <a href="/wiki/Haskell_(programming_language)" title="Haskell (programming language)">Haskell</a>, including <a href="/wiki/Anonymous_function" title="Anonymous function">anonymous functions</a>, <a href="/wiki/Type_inference" title="Type inference">type inference</a>, <a href="/wiki/List_comprehension" title="List comprehension">list comprehensions</a> (known in Scala as "for-comprehensions"), <a href="/wiki/Lazy_initialization" title="Lazy initialization">lazy initialization</a>, extensive language and library support for avoiding <a href="/wiki/Side_effect_(computer_science)" title="Side effect (computer science)">side-effects</a>, for <a href="/wiki/Pattern_matching" title="Pattern matching">pattern matching</a>, case classes, <a href="/wiki/Delimited_continuation" title="Delimited continuation">delimited continuations</a>, <a href="/wiki/Higher-order_type_operator" title="Higher-order type operator" class="mw-redirect">higher-order types</a>, much better support for <a href="/wiki/Covariance_and_contravariance_(computer_science)" title="Covariance and contravariance (computer science)">covariance and contravariance</a>. Scala has a <i>unified type system</i> (as in <a href="/wiki/C_Sharp_(programming_language)" title="C Sharp (programming language)">C#</a>, but unlike in Java), where all types, including primitive types like <a href="/wiki/Integer" title="Integer">integer</a> and <a href="/wiki/Boolean_data_type" title="Boolean data type">boolean</a>, are subclasses of the type <code>Any</code>. Scala likewise has other features present in C# but not Java, including <a href="/wiki/Anonymous_type" title="Anonymous type">anonymous types</a>, <a href="/wiki/Operator_overloading" title="Operator overloading">operator overloading</a>, optional parameters, <a href="/wiki/Named_parameter" title="Named parameter">named parameters</a>, <a href="/wiki/Raw_string" title="Raw string" class="mw-redirect">raw strings</a> (that may be multi-line in Scala), and no <a href="/wiki/Checked_exception" title="Checked exception" class="mw-redirect">checked exceptions</a>.</p>
<p>The name Scala is a <a href="/wiki/Portmanteau" title="Portmanteau">portmanteau</a> of "scalable" and "language", signifying that it is designed to grow with the demands of its users. <a href="/wiki/James_Strachan_(programmer)" title="James Strachan (programmer)">James Strachan</a>, the creator of <a href="/wiki/Groovy_(programming_language)" title="Groovy (programming language)">Groovy</a>, described Scala as a possible successor to <a href="/wiki/Java_(programming_language)" title="Java (programming language)">Java</a>.<sup id="cite_ref-7" class="reference"><a href="#cite_note-7"><span>[</span>7<span>]</span></a></sup></p>
<div id="toc" class="toc">
<div id="toctitle">
<h2>Contents</h2>
</div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#History"><span class="tocnumber">1</span> <span class="toctext">History</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#Platforms_and_license"><span class="tocnumber">2</span> <span class="toctext">Platforms and license</span></a></li>
<li class="toclevel-1 tocsection-3"><a href="#Examples"><span class="tocnumber">3</span> <span class="toctext">Examples</span></a>
<ul>
<li class="toclevel-2 tocsection-4"><a href="#.22Hello_World.22_example"><span class="tocnumber">3.1</span> <span class="toctext">"Hello World" example</span></a></li>
<li class="toclevel-2 tocsection-5"><a href="#A_basic_example"><span class="tocnumber">3.2</span> <span class="toctext">A basic example</span></a></li>
<li class="toclevel-2 tocsection-6"><a href="#An_example_with_classes"><span class="tocnumber">3.3</span> <span class="toctext">An example with classes</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-7"><a href="#Features_.28with_reference_to_Java.29"><span class="tocnumber">4</span> <span class="toctext">Features (with reference to Java)</span></a>
<ul>
<li class="toclevel-2 tocsection-8"><a href="#Syntactic_flexibility"><span class="tocnumber">4.1</span> <span class="toctext">Syntactic flexibility</span></a></li>
<li class="toclevel-2 tocsection-9"><a href="#Unified_type_system"><span class="tocnumber">4.2</span> <span class="toctext">Unified type system</span></a></li>
<li class="toclevel-2 tocsection-10"><a href="#For-expressions"><span class="tocnumber">4.3</span> <span class="toctext">For-expressions</span></a></li>
<li class="toclevel-2 tocsection-11"><a href="#Functional_tendencies"><span class="tocnumber">4.4</span> <span class="toctext">Functional tendencies</span></a>
<ul>
<li class="toclevel-3 tocsection-12"><a href="#Everything_is_an_expression"><span class="tocnumber">4.4.1</span> <span class="toctext">Everything is an expression</span></a></li>
<li class="toclevel-3 tocsection-13"><a href="#Type_inference"><span class="tocnumber">4.4.2</span> <span class="toctext">Type inference</span></a></li>
<li class="toclevel-3 tocsection-14"><a href="#Anonymous_functions"><span class="tocnumber">4.4.3</span> <span class="toctext">Anonymous functions</span></a></li>
<li class="toclevel-3 tocsection-15"><a href="#Immutability"><span class="tocnumber">4.4.4</span> <span class="toctext">Immutability</span></a></li>
<li class="toclevel-3 tocsection-16"><a href="#Lazy_.28non-strict.29_evaluation"><span class="tocnumber">4.4.5</span> <span class="toctext">Lazy (non-strict) evaluation</span></a></li>
<li class="toclevel-3 tocsection-17"><a href="#Tail_recursion"><span class="tocnumber">4.4.6</span> <span class="toctext">Tail recursion</span></a></li>
<li class="toclevel-3 tocsection-18"><a href="#Case_classes_and_pattern_matching"><span class="tocnumber">4.4.7</span> <span class="toctext">Case classes and pattern matching</span></a></li>
<li class="toclevel-3 tocsection-19"><a href="#Partial_functions"><span class="tocnumber">4.4.8</span> <span class="toctext">Partial functions</span></a></li>
</ul>
</li>
<li class="toclevel-2 tocsection-20"><a href="#Object-oriented_extensions"><span class="tocnumber">4.5</span> <span class="toctext">Object-oriented extensions</span></a></li>
<li class="toclevel-2 tocsection-21"><a href="#Expressive_type_system"><span class="tocnumber">4.6</span> <span class="toctext">Expressive type system</span></a></li>
<li class="toclevel-2 tocsection-22"><a href="#Type_enrichment"><span class="tocnumber">4.7</span> <span class="toctext">Type enrichment</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-23"><a href="#Concurrency"><span class="tocnumber">5</span> <span class="toctext">Concurrency</span></a></li>
<li class="toclevel-1 tocsection-24"><a href="#Testing"><span class="tocnumber">6</span> <span class="toctext">Testing</span></a></li>
<li class="toclevel-1 tocsection-25"><a href="#Versions"><span class="tocnumber">7</span> <span class="toctext">Versions</span></a></li>
<li class="toclevel-1 tocsection-26"><a href="#Comparison_with_other_JVM_languages"><span class="tocnumber">8</span> <span class="toctext">Comparison with other JVM languages</span></a></li>
<li class="toclevel-1 tocsection-27"><a href="#Adoption"><span class="tocnumber">9</span> <span class="toctext">Adoption</span></a>
<ul>
<li class="toclevel-2 tocsection-28"><a href="#Language_rankings"><span class="tocnumber">9.1</span> <span class="toctext">Language rankings</span></a></li>
<li class="toclevel-2 tocsection-29"><a href="#Companies"><span class="tocnumber">9.2</span> <span class="toctext">Companies</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-30"><a href="#See_also"><span class="tocnumber">10</span> <span class="toctext">See also</span></a></li>
<li class="toclevel-1 tocsection-31"><a href="#References"><span class="tocnumber">11</span> <span class="toctext">References</span></a></li>
<li class="toclevel-1 tocsection-32"><a href="#Further_reading"><span class="tocnumber">12</span> <span class="toctext">Further reading</span></a></li>
<li class="toclevel-1 tocsection-33"><a href="#External_links"><span class="tocnumber">13</span> <span class="toctext">External links</span></a></li>
</ul>
</div>
<h2><span class="mw-headline" id="History">History</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=1" title="Edit section: History">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>The design of Scala started in 2001 at the <a href="/wiki/%C3%89cole_Polytechnique_F%C3%A9d%C3%A9rale_de_Lausanne" title="École Polytechnique Fédérale de Lausanne">École Polytechnique Fédérale de Lausanne</a> (EPFL) by <a href="/wiki/Martin_Odersky" title="Martin Odersky">Martin Odersky</a>, following on from work on Funnel, a programming language combining ideas from functional programming and <a href="/wiki/Petri_net" title="Petri net">Petri nets</a>.<sup id="cite_ref-history-of-scala_8-0" class="reference"><a href="#cite_note-history-of-scala-8"><span>[</span>8<span>]</span></a></sup> Odersky had previously worked on <a href="/wiki/Generic_Java_(programming_language)" title="Generic Java (programming language)" class="mw-redirect">Generic Java</a> and <a href="/wiki/Javac" title="Javac">javac</a>, Sun's Java compiler.<sup id="cite_ref-history-of-scala_8-1" class="reference"><a href="#cite_note-history-of-scala-8"><span>[</span>8<span>]</span></a></sup></p>
<p>Scala was released late 2003/early 2004 on the <a href="/wiki/Java_platform" title="Java platform" class="mw-redirect">Java</a> platform, and on the <a href="/wiki/.NET_Framework" title=".NET Framework">.NET platform</a> in June 2004.<sup id="cite_ref-overview_5-2" class="reference"><a href="#cite_note-overview-5"><span>[</span>5<span>]</span></a></sup><sup id="cite_ref-history-of-scala_8-2" class="reference"><a href="#cite_note-history-of-scala-8"><span>[</span>8<span>]</span></a></sup><sup id="cite_ref-spec_9-0" class="reference"><a href="#cite_note-spec-9"><span>[</span>9<span>]</span></a></sup> A second version of the language, v2.0, was released in March 2006.<sup id="cite_ref-overview_5-3" class="reference"><a href="#cite_note-overview-5"><span>[</span>5<span>]</span></a></sup> The .NET support was officially dropped in 2012.<sup id="cite_ref-10" class="reference"><a href="#cite_note-10"><span>[</span>10<span>]</span></a></sup></p>
<p>On 17 January 2011 the Scala team won a five year research grant of over €2.3 million from the <a href="/wiki/European_Research_Council" title="European Research Council">European Research Council</a>.<sup id="cite_ref-11" class="reference"><a href="#cite_note-11"><span>[</span>11<span>]</span></a></sup> On 12 May 2011, Odersky and collaborators launched <a href="/wiki/Typesafe_Inc." title="Typesafe Inc.">Typesafe Inc.</a>, a company to provide commercial support, training, and services for Scala. Typesafe received a $3 million investment from <a href="/wiki/Greylock_Partners" title="Greylock Partners">Greylock Partners</a>.<sup id="cite_ref-12" class="reference"><a href="#cite_note-12"><span>[</span>12<span>]</span></a></sup><sup id="cite_ref-13" class="reference"><a href="#cite_note-13"><span>[</span>13<span>]</span></a></sup><sup id="cite_ref-14" class="reference"><a href="#cite_note-14"><span>[</span>14<span>]</span></a></sup><sup id="cite_ref-15" class="reference"><a href="#cite_note-15"><span>[</span>15<span>]</span></a></sup></p>
<h2><span class="mw-headline" id="Platforms_and_license">Platforms and license</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=2" title="Edit section: Platforms and license">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>Scala runs on the <a href="/wiki/Java_platform" title="Java platform" class="mw-redirect">Java platform</a> (<a href="/wiki/Java_Virtual_Machine" title="Java Virtual Machine" class="mw-redirect">Java Virtual Machine</a>) and is compatible with existing <a href="/wiki/Java_(programming_language)" title="Java (programming language)">Java</a> programs. It also runs on <a href="/wiki/Android_(operating_system)" title="Android (operating system)">Android</a> smartphones.<sup id="cite_ref-16" class="reference"><a href="#cite_note-16"><span>[</span>16<span>]</span></a></sup> There was an alternative implementation for the <a href="/wiki/.NET_platform" title=".NET platform" class="mw-redirect">.NET platform</a>,<sup id="cite_ref-.netsupport_17-0" class="reference"><a href="#cite_note-.netsupport-17"><span>[</span>17<span>]</span></a></sup><sup id="cite_ref-.netsupport2_18-0" class="reference"><a href="#cite_note-.netsupport2-18"><span>[</span>18<span>]</span></a></sup> but it was dropped.</p>
<p>The Scala software distribution, including compiler and libraries, is released under a <a href="/wiki/BSD_license" title="BSD license" class="mw-redirect">BSD license</a>.<sup id="cite_ref-19" class="reference"><a href="#cite_note-19"><span>[</span>19<span>]</span></a></sup></p>
<h2><span class="mw-headline" id="Examples">Examples</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=3" title="Edit section: Examples">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h3><span class="mw-headline" id=".22Hello_World.22_example">"Hello World" example</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=4" title="Edit section: "Hello World" example">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<p>Here is the classic <a href="/wiki/Hello_World_program" title="Hello World program" class="mw-redirect">Hello World program</a> written in Scala:</p>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="scala source-scala">
<pre class="de1">
<span class="kw1">object</span> HelloWorld <span class="kw1">extends</span> App <span class="br0">{</span>
println<span class="br0">(</span><span class="st0">"Hello, World!"</span><span class="br0">)</span>
<span class="br0">}</span>
</pre></div>
</div>
<p>Unlike the <a href="/wiki/Java_(programming_language)#Hello_world" title="Java (programming language)">stand-alone Hello World application for Java</a>, there is no class declaration and nothing is declared to be static; a <a href="/wiki/Singleton_pattern" title="Singleton pattern">singleton object</a> created with the <b>object</b> keyword is used instead.</p>
<p>With the program saved in a file named <code>HelloWorld.scala</code>, it can be compiled from the command line:</p>
<p><code>$ scalac HelloWorld.scala</code></p>
<p>To run it:</p>
<p><code>$ scala HelloWorld</code> (You may need to use the "-cp" key to set the classpath like in Java).</p>
<p>This is analogous to the process for compiling and running Java code. Indeed, Scala's compilation and execution model is identical to that of Java, making it compatible with Java build tools such as <a href="/wiki/Apache_Ant" title="Apache Ant">Ant</a>.</p>
<p>A shorter version of the "Hello World" Scala program is:</p>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="scala source-scala">
<pre class="de1">
println<span class="br0">(</span><span class="st0">"Hello, World!"</span><span class="br0">)</span>
</pre></div>
</div>
<p>Saved in a file named <code>HelloWorld2.scala</code>, this can be run as a script without prior compilation using:</p>
<p><code>$ scala HelloWorld2.scala</code></p>
<p>Commands can also be fed directly into the Scala interpreter, using the option <b>-e</b>:</p>
<p><code>$ scala -e 'println("Hello, World!")'</code></p>
<h3><span class="mw-headline" id="A_basic_example">A basic example</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=5" title="Edit section: A basic example">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<p>The following example shows the differences between Java and Scala syntax:</p>
<table>
<tr>
<td>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="java source-java">
<pre class="de1">
<span class="co1">// Java:</span>
<span class="kw4">int</span> mathFunction<span class="br0">(</span><span class="kw4">int</span> num<span class="br0">)</span> <span class="br0">{</span>
<span class="kw4">int</span> numSquare <span class="sy0">=</span> num<span class="sy0">*</span>num<span class="sy0">;</span>
<span class="kw1">return</span> <span class="br0">(</span><span class="kw4">int</span><span class="br0">)</span> <span class="br0">(</span><span class="kw3">Math</span>.<span class="me1">cbrt</span><span class="br0">(</span>numSquare<span class="br0">)</span> <span class="sy0">+</span>
<span class="kw3">Math</span>.<span class="me1">log</span><span class="br0">(</span>numSquare<span class="br0">)</span><span class="br0">)</span><span class="sy0">;</span>
<span class="br0">}</span>
</pre></div>
</div>
</td>
</tr>
<tr>
<td>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="scala source-scala">
<pre class="de1">
<span class="co1">// Scala: Direct conversion from Java</span>
<span class="co1">// no import needed; scala.math</span>
<span class="co1">// already imported as `math`</span>
<span class="kw1">def</span> mathFunction<span class="br0">(</span>num<span class="sy0">:</span> Int<span class="br0">)</span><span class="sy0">:</span> Int <span class="sy0">=</span> <span class="br0">{</span>
<span class="kw1">var</span> numSquare<span class="sy0">:</span> Int <span class="sy0">=</span> num<span class="sy0">*</span>num
<span class="kw1">return</span> <span class="br0">(</span>math.<span class="me1">cbrt</span><span class="br0">(</span>numSquare<span class="br0">)</span> + math.<span class="me1">log</span><span class="br0">(</span>numSquare<span class="br0">)</span><span class="br0">)</span>.
<span class="me1">asInstanceOf</span><span class="br0">[</span>Int<span class="br0">]</span>
<span class="br0">}</span>
</pre></div>
</div>
</td>
<td>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="scala source-scala">
<pre class="de1">
<span class="co1">// Scala: More idiomatic</span>
<span class="co1">// Uses type inference, omits `return` statement,</span>
<span class="co1">// uses `toInt()` method, normally called without parens</span>
<span class="kw1">import</span> math.<span class="sy0">_</span>
<span class="kw1">def</span> intRoot23<span class="br0">(</span>num<span class="sy0">:</span> Int<span class="br0">)</span> <span class="sy0">=</span> <span class="br0">{</span>
<span class="kw1">val</span> numSquare <span class="sy0">=</span> num<span class="sy0">*</span>num
<span class="br0">(</span>cbrt<span class="br0">(</span>numSquare<span class="br0">)</span> + log<span class="br0">(</span>numSquare<span class="br0">)</span><span class="br0">)</span>.<span class="me1">toInt</span>
<span class="br0">}</span>
</pre></div>
</div>
</td>
</tr>
</table>
<p>Note in particular the syntactic differences shown by this code:</p>
<ol>
<li>Scala does not require semicolons.</li>
<li>Value types are capitalized: <code>Int, Double, Boolean</code> instead of <code>int, double, boolean</code>.</li>
<li>Parameter and return types follow, as in <a href="/wiki/Pascal_(programming_language)" title="Pascal (programming language)">Pascal</a>, rather than precede as in <a href="/wiki/C_(programming_language)" title="C (programming language)">C</a>.</li>
<li>Functions must be preceded by <code>def</code>.</li>
<li>Local or class variables must be preceded by <code>val</code> (indicates an unmodifiable variable) or <code>var</code> (indicates a modifiable variable).</li>
<li>The <code>return</code> operator is unnecessary in a function (although allowed); the value of the last executed statement or expression is normally the function's value.</li>
<li>Instead of the Java cast operator <code>(Type) foo</code>, Scala uses <code>foo.asInstanceOf[Type]</code>, or a specialized function such as <code>toDouble</code> or <code>toInt</code>.</li>
<li>Instead of Java's <code>import foo.*;</code>, Scala uses <code>import foo._</code>.</li>
<li>Function or method <code>foo()</code> can also be called as just <code>foo</code>; method <code>thread.send(signo)</code> can also be called as just <code>thread send signo</code>; and method <code>foo.toString()</code> can also be called as just <code>foo toString</code>.</li>
</ol>
<p>(These syntactic relaxations are designed to allow support for <a href="/wiki/Domain-specific_language" title="Domain-specific language">domain-specific languages</a>.)</p>
<p>Some other basic syntactic differences:</p>
<ol>
<li>Array references are written like function calls, e.g. <code>array(i)</code> rather than <code>array[i]</code>. (Internally in Scala, both arrays and functions are conceptualized as kinds of mathematical mappings from one object to another.)</li>
<li>Generic types are written as e.g. <code>List[String]</code> rather than Java's <code>List<String></code>.</li>
<li>Instead of the pseudo-type <code>void</code>, Scala has the actual <a href="/wiki/Singleton_pattern" title="Singleton pattern">singleton class</a> <code>Unit</code> (see below).</li>
</ol>
<h3><span class="mw-headline" id="An_example_with_classes">An example with classes</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=6" title="Edit section: An example with classes">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<p>The following example contrasts Java and Scala ways of defining classes.</p>
<table>
<tr>
<td>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="java source-java">
<pre class="de1">
<span class="co1">// Java:</span>
<span class="kw1">public</span> <span class="kw1">class</span> <span class="kw3">Point</span> <span class="br0">{</span>
<span class="kw1">private</span> <span class="kw4">double</span> x, y<span class="sy0">;</span>
<span class="kw1">public</span> <span class="kw3">Point</span><span class="br0">(</span><span class="kw1">final</span> <span class="kw4">double</span> X, <span class="kw1">final</span> <span class="kw4">double</span> Y<span class="br0">)</span> <span class="br0">{</span>
x <span class="sy0">=</span> X<span class="sy0">;</span>
y <span class="sy0">=</span> Y<span class="sy0">;</span>
<span class="br0">}</span>
<span class="kw1">public</span> <span class="kw4">double</span> x<span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span>
<span class="kw1">return</span> x<span class="sy0">;</span>
<span class="br0">}</span>
<span class="kw1">public</span> <span class="kw4">double</span> y<span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span>
<span class="kw1">return</span> y<span class="sy0">;</span>
<span class="br0">}</span>
<span class="kw1">public</span> <span class="kw3">Point</span><span class="br0">(</span>
<span class="kw1">final</span> <span class="kw4">double</span> X, <span class="kw1">final</span> <span class="kw4">double</span> Y,
<span class="kw1">final</span> <span class="kw4">boolean</span> ADD2GRID
<span class="br0">)</span> <span class="br0">{</span>
<span class="kw1">this</span><span class="br0">(</span>X, Y<span class="br0">)</span><span class="sy0">;</span>
<span class="kw1">if</span> <span class="br0">(</span>ADD2GRID<span class="br0">)</span>
grid.<span class="me1">add</span><span class="br0">(</span><span class="kw1">this</span><span class="br0">)</span><span class="sy0">;</span>
<span class="br0">}</span>
<span class="kw1">public</span> <span class="kw3">Point</span><span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span>
<span class="kw1">this</span><span class="br0">(</span><span class="nu0">0.0</span>, <span class="nu0">0.0</span><span class="br0">)</span><span class="sy0">;</span>
<span class="br0">}</span>
<span class="kw4">double</span> distanceToPoint<span class="br0">(</span><span class="kw1">final</span> <span class="kw3">Point</span> OTHER<span class="br0">)</span> <span class="br0">{</span>
<span class="kw1">return</span> distanceBetweenPoints<span class="br0">(</span>x, y,
OTHER.<span class="me1">x</span>, OTHER.<span class="me1">y</span><span class="br0">)</span><span class="sy0">;</span>
<span class="br0">}</span>
<span class="kw1">private</span> <span class="kw1">static</span> Grid grid <span class="sy0">=</span> <span class="kw1">new</span> Grid<span class="br0">(</span><span class="br0">)</span><span class="sy0">;</span>
<span class="kw1">static</span> <span class="kw4">double</span> distanceBetweenPoints<span class="br0">(</span>
<span class="kw1">final</span> <span class="kw4">double</span> X1, <span class="kw1">final</span> <span class="kw4">double</span> Y1,
<span class="kw1">final</span> <span class="kw4">double</span> X2, <span class="kw1">final</span> <span class="kw4">double</span> Y2
<span class="br0">)</span> <span class="br0">{</span>
<span class="kw4">double</span> xDist <span class="sy0">=</span> X1 <span class="sy0">-</span> X2<span class="sy0">;</span>
<span class="kw4">double</span> yDist <span class="sy0">=</span> Y1 <span class="sy0">-</span> Y2<span class="sy0">;</span>
<span class="kw1">return</span> <span class="kw3">Math</span>.<span class="me1">sqrt</span><span class="br0">(</span>xDist<span class="sy0">*</span>xDist <span class="sy0">+</span> yDist<span class="sy0">*</span>yDist<span class="br0">)</span><span class="sy0">;</span>
<span class="br0">}</span>
<span class="br0">}</span>
</pre></div>
</div>
</td>
<td>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="scala source-scala">
<pre class="de1">
<span class="co1">// Scala</span>
<span class="kw1">class</span> Point<span class="br0">(</span>
<span class="kw1">val</span> x<span class="sy0">:</span> Double, <span class="kw1">val</span> y<span class="sy0">:</span> Double,
addToGrid<span class="sy0">:</span> Boolean <span class="sy0">=</span> <span class="kw1">false</span>
<span class="br0">)</span> <span class="br0">{</span>
<span class="kw1">import</span> Point.<span class="sy0">_</span>
<span class="kw1">if</span> <span class="br0">(</span>addToGrid<span class="br0">)</span>
grid.<span class="me1">add</span><span class="br0">(</span><span class="kw1">this</span><span class="br0">)</span>
<span class="kw1">def</span> <span class="kw1">this</span><span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span>
<span class="kw1">this</span><span class="br0">(</span><span class="nu0">0.0</span>, <span class="nu0">0.0</span><span class="br0">)</span>
<span class="br0">}</span>
<span class="kw1">def</span> distanceToPoint<span class="br0">(</span>other<span class="sy0">:</span> Point<span class="br0">)</span> <span class="sy0">=</span>
distanceBetweenPoints<span class="br0">(</span>x, y, other.<span class="me1">x</span>, other.<span class="me1">y</span><span class="br0">)</span>
<span class="br0">}</span>
<span class="kw1">object</span> Point <span class="br0">{</span>
<span class="kw1">private</span> <span class="kw1">val</span> grid <span class="sy0">=</span> <span class="kw1">new</span> Grid<span class="br0">(</span><span class="br0">)</span>
<span class="kw1">def</span> distanceBetweenPoints<span class="br0">(</span>x1<span class="sy0">:</span> Double, y1<span class="sy0">:</span> Double,
x2<span class="sy0">:</span> Double, y2<span class="sy0">:</span> Double<span class="br0">)</span> <span class="sy0">=</span> <span class="br0">{</span>
<span class="kw1">val</span> xDist <span class="sy0">=</span> x1 - x2
<span class="kw1">val</span> yDist <span class="sy0">=</span> y1 - y2
math.<span class="me1">sqrt</span><span class="br0">(</span>xDist<span class="sy0">*</span>xDist + yDist<span class="sy0">*</span>yDist<span class="br0">)</span>
<span class="br0">}</span>
<span class="br0">}</span>
</pre></div>
</div>
</td>
</tr>
</table>
<p>The above code shows some of the conceptual differences between Java and Scala's handling of classes:</p>
<ol>
<li>Scala has no static variables or methods. Instead, it has <i>singleton objects</i>, which are essentially classes with only one object in the class. Singleton objects are declared using <code>object</code> instead of <code>class</code>. It is common to place static variables and methods in a singleton object with the same name as the class name, which is then known as a <i>companion object</i>. (The underlying class for the singleton object has a <code>$</code> appended. Hence, for <code>class Foo</code> with companion object <code>object Foo</code>, under the hood there's a class <code>Foo$</code> containing the companion object's code, and a single object of this class is created, using the <a href="/wiki/Singleton_pattern" title="Singleton pattern">singleton pattern</a>.)</li>
<li>In place of constructor parameters, Scala has <i>class parameters</i>, which are placed on the class itself, similar to parameters to a function. When declared with a <code>val</code> or <code>var</code> modifier, fields are also defined with the same name, and automatically initialized from the class parameters. (Under the hood, external access to public fields always goes through accessor (getter) and mutator (setter) methods, which are automatically created. The accessor function has the same name as the field, which is why it's unnecessary in the above example to explicitly declare accessor methods.) Note that alternative constructors can also be declared, as in Java. Code that would go into the default constructor (other than initializing the member variables) goes directly at class level.</li>
<li>Default visibility in Scala is <code>public</code>.</li>
</ol>
<h2><span class="mw-headline" id="Features_.28with_reference_to_Java.29">Features (with reference to Java)</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=7" title="Edit section: Features (with reference to Java)">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>Scala has the same compilation model as <a href="/wiki/Java_platform" title="Java platform" class="mw-redirect">Java</a> and <a href="/wiki/C_Sharp_(programming_language)" title="C Sharp (programming language)">C#</a> (separate compilation, <a href="/wiki/Java_Classloader" title="Java Classloader">dynamic class loading</a>), so Scala code can call <a href="/wiki/Java_platform" title="Java platform" class="mw-redirect">Java</a> libraries (or .NET libraries in the .NET implementation).</p>
<p>Scala's operational characteristics are the same as <a href="/wiki/Java_platform" title="Java platform" class="mw-redirect">Java's</a>. The Scala compiler generates byte code that is nearly identical to that generated by the <a href="/wiki/Java_platform" title="Java platform" class="mw-redirect">Java</a> compiler. In fact, Scala code can be <a href="/wiki/Decompiler" title="Decompiler">decompiled</a> to readable <a href="/wiki/Java_platform" title="Java platform" class="mw-redirect">Java</a> code, with the exception of certain constructor operations. To the JVM, Scala code and <a href="/wiki/Java_platform" title="Java platform" class="mw-redirect">Java</a> code are indistinguishable. The only difference is a single extra runtime library, <code>scala-library.jar</code>.<sup id="cite_ref-20" class="reference"><a href="#cite_note-20"><span>[</span>20<span>]</span></a></sup></p>
<p>Scala adds a large number of features compared with Java, and has some fundamental differences in its underlying model of expressions and types, which make the language theoretically cleaner and eliminate a number of "<a href="/wiki/Corner_cases" title="Corner cases" class="mw-redirect">corner cases</a>" in Java. From the Scala perspective, this is practically important because a number of additional features in Scala are also available in C#. Examples include:</p>
<h3><span class="mw-headline" id="Syntactic_flexibility">Syntactic flexibility</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=8" title="Edit section: Syntactic flexibility">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<p>As mentioned above, Scala has a good deal of syntactic flexibility, compared with Java. The following are some examples:</p>
<ol>
<li>Semicolons are unnecessary; lines are automatically joined if they begin or end with a token that cannot normally come in this position, or if there are unclosed parentheses or brackets.</li>
<li>Any method can be used as an infix operator, e.g. <code>"%d apples".format(num)</code> and <code>"%d apples" format num</code> are equivalent. In fact, arithmetic operators like <code>+</code> and <code><<</code> are treated just like any other methods, since function names are allowed to consist of sequences of arbitrary symbols (with a few exceptions made for things like parens, brackets and braces that must be handled specially); the only special treatment that such symbol-named methods undergo concerns the handling of precedence.</li>
<li>Methods <code>apply</code> and <code>update</code> have syntactic short forms. <code>foo()</code>—where <code>foo</code> is a value (singleton object or class instance)—is short for <code>foo.apply()</code>, and <code>foo() = 42</code> is short for <code>foo.update(42)</code>. Similarly, <code>foo(42)</code> is short for <code>foo.apply(42)</code>, and <code>foo(4) = 2</code> is short for <code>foo.update(4, 2)</code>. This is used for collection classes and extends to many other cases, such as <a href="/wiki/Software_transactional_memory" title="Software transactional memory">STM</a> cells.</li>
<li>Scala distinguishes between no-parens (<code>def foo = 42</code>) and empty-parens (<code>def foo() = 42</code>) methods. When calling an empty-parens method, the parentheses may be omitted, which is useful when calling into Java libraries which do not know this distinction, e.g., using <code>foo.toString</code> instead of <code>foo.toString()</code>. By convention a method should be defined with empty-parens when it performs <a href="/wiki/Side_effect_(computer_science)" title="Side effect (computer science)">side effects</a>.</li>
<li>Method names ending in colon (<code>:</code>) expect the argument on the left-hand-side and the receiver on the right-hand-side. For example, the <code>4 :: 2 :: Nil</code> is the same as <code>Nil.::(2).::(4)</code>, the first form corresponding visually to the result (a list with first element 4 and second element 2).</li>
<li>Class body variables can be transparently implemented as separate getter and setter methods. For <code>trait FooLike { var bar: Int }</code>, an implementation may be <code>object Foo extends FooLike { private var x = 0; def bar = x; def bar_=(value: Int) { x = value }}</code>. The call site will still be able to use a concise <code>foo.bar = 42</code>.</li>
<li>The use of curly braces instead of parentheses is allowed in method calls. This allows pure library implementations of new control structures.<sup id="cite_ref-21" class="reference"><a href="#cite_note-21"><span>[</span>21<span>]</span></a></sup> For example, <code>breakable { ... if (...) break() ... }</code> looks as if <code>breakable</code> was a language defined keyword, but really is just a method taking a <a href="/wiki/Thunk_(functional_programming)" title="Thunk (functional programming)">thunk</a> argument. Methods that take thunks or functions often place these in a second parameter list, allowing to mix parentheses and curly braces syntax: <code>Vector.fill(4) { math.random }</code> is the same as <code>Vector.fill(4)(math.random)</code>. The curly braces variant allows the expression to span multiple lines.</li>
<li>For-expressions (explained further down) can accommodate any type that defines monadic methods such as <code>map</code>, <code>flatMap</code> and <code>filter</code>.</li>
</ol>
<p>By themselves, these may seem like questionable choices, but collectively they serve the purpose of allowing <a href="/wiki/Domain-specific_language" title="Domain-specific language">domain-specific languages</a> to be defined in Scala without needing to extend the compiler. For example, <a href="/wiki/Erlang_(programming_language)" title="Erlang (programming language)">Erlang</a>'s special syntax for sending a message to an actor, i.e. <code>actor ! message</code> can be (and is) implemented in a Scala library without needing language extensions.</p>
<h3><span class="mw-headline" id="Unified_type_system">Unified type system</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=9" title="Edit section: Unified type system">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<p>Java makes a sharp distinction between primitive types (e.g. <code>int</code> and <code>boolean</code>) and reference types (any <a href="/wiki/Class_(computer_programming)" title="Class (computer programming)">class</a>). Only reference types are part of the inheritance scheme, deriving from <code>java.lang.Object</code>. In Scala, however, all types inherit from a top-level class <code>Any</code>, whose immediate children are <code>AnyVal</code> (value types, such as <code>Int</code> and <code>Boolean</code>) and <code>AnyRef</code> (reference types, as in Java). This means that the Java distinction between primitive types and boxed types (e.g. <code>int</code> vs. <code>Integer</code>) is not present in Scala; boxing and unboxing is completely transparent to the user. Scala 2.10 allows for new value types to be defined by the user.</p>
<h3><span class="mw-headline" id="For-expressions">For-expressions</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=10" title="Edit section: For-expressions">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<p>Instead of the Java "foreach" loops for looping through an iterator, Scala has a much more powerful concept of <code>for</code>-expressions. These are similar to <a href="/wiki/List_comprehension" title="List comprehension">list comprehensions</a> in a languages such as Haskell, or a combination of list comprehensions and <a href="/wiki/Python_syntax_and_semantics#Generator_expressions" title="Python syntax and semantics">generator expressions</a> in <a href="/wiki/Python_(programming_language)" title="Python (programming language)">Python</a>. For-expressions using the <code>yield</code> keyword allow a new <a href="/wiki/Collection_(computer_science)" title="Collection (computer science)" class="mw-redirect">collection</a> to be generated by iterating over an existing one, returning a new collection of the same type. They are translated by the compiler into a series of <code>map</code>, <code>flatMap</code> and <code>filter</code> calls. Where <code>yield</code> is not used, the code approximates to an imperative-style loop, by translating to <code>foreach</code>.</p>
<p>A simple example is:</p>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="scala source-scala">
<pre class="de1">
<span class="kw1">val</span> s <span class="sy0">=</span> <span class="kw1">for</span> <span class="br0">(</span>x <span class="sy0"><</span>- <span class="nu0">1</span> to <span class="nu0">25</span> <span class="kw1">if</span> x<span class="sy0">*</span>x <span class="sy0">></span> <span class="nu0">50</span><span class="br0">)</span> <span class="kw1">yield</span> <span class="nu0">2</span><span class="sy0">*</span>x
</pre></div>
</div>
<p>The result of running it is the following vector:</p>
<dl>
<dd><code>Vector(16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50)</code></dd>
</dl>
<p>(Note that the expression <code>1 to 25</code> is not special syntax. The method <code>to</code> is rather defined in the standard Scala library as an extension method on integers, using a technique known as implicit conversions<sup id="cite_ref-artima1_22-0" class="reference"><a href="#cite_note-artima1-22"><span>[</span>22<span>]</span></a></sup> that allows new methods to be added to existing types.)</p>
<p>A more complex example of iterating over a map is:</p>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="scala source-scala">
<pre class="de1">
<span class="co1">// Given a map specifying Twitter users mentioned in a set of tweets,</span>
<span class="co1">// and number of times each user was mentioned, look up the users</span>
<span class="co1">// in a map of known politicians, and return a new map giving only the</span>
<span class="co1">// Democratic politicians (as objects, rather than strings).</span>
<span class="kw1">val</span> dem<span class="sy0">_</span>mentions <span class="sy0">=</span> <span class="kw1">for</span> <span class="br0">{</span>
<span class="br0">(</span>mention, times<span class="br0">)</span> <span class="sy0"><</span>- mentions
account <span class="sy0"><</span>- accounts.<span class="me1">get</span><span class="br0">(</span>mention<span class="br0">)</span>
<span class="kw1">if</span> account.<span class="me1">party</span> <span class="sy0">==</span> <span class="st0">"Democrat"</span>
<span class="br0">}</span> <span class="kw1">yield</span> <span class="br0">(</span>account, times<span class="br0">)</span>
</pre></div>
</div>
<p>Note that the expression <code>(mention, times) <- mentions</code> is actually an example of <a href="/wiki/Pattern_matching" title="Pattern matching">pattern matching</a> (see below). Iterating over a map returns a set of key-value <a href="/wiki/Tuple_(computer_science)" title="Tuple (computer science)" class="mw-redirect">tuples</a>, and pattern-matching allows the tuples to easily be destructured into separate variables for the key and value. Similarly, the result of the comprehension also returns key-value tuples, which are automatically built back up into a map because the source object (from the variable <code>mentions</code>) is a map. Note that if <code>mentions</code> instead held a list, set, array or other collection of tuples, exactly the same code above would yield a new collection of the same type.</p>
<h3><span class="mw-headline" id="Functional_tendencies">Functional tendencies</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=11" title="Edit section: Functional tendencies">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<p>While supporting all of the object-oriented features available in Java (and in fact, augmenting them in various ways), Scala also provides a large number of capabilities that are normally found only in <a href="/wiki/Functional_programming" title="Functional programming">functional programming</a> languages. Together, these features allow Scala programs to be written in an almost completely functional style, and also allow functional and object-oriented styles to be mixed.</p>
<p>Examples are:</p>
<ul>
<li>No distinction between statements and expressions</li>
<li><a href="/wiki/Type_inference" title="Type inference">Type inference</a></li>
<li><a href="/wiki/Anonymous_function" title="Anonymous function">Anonymous functions</a> with capturing semantics (i.e. <a href="/wiki/Closure_(computer_science)" title="Closure (computer science)">closures</a>)</li>
<li>Immutable variables and objects</li>
<li><a href="/wiki/Lazy_evaluation" title="Lazy evaluation">Lazy evaluation</a></li>
<li><a href="/wiki/Delimited_continuation" title="Delimited continuation">Delimited continuations</a> (since 2.8)</li>
<li><a href="/wiki/Higher-order_function" title="Higher-order function">Higher-order functions</a></li>
<li>Nested functions</li>
<li><a href="/wiki/Currying" title="Currying">Currying</a></li>
<li><a href="/wiki/Pattern_matching" title="Pattern matching">Pattern matching</a></li>
<li><a href="/wiki/Algebraic_data_types" title="Algebraic data types" class="mw-redirect">Algebraic data types</a> (through "case classes")</li>
<li><a href="/wiki/Tuple_(computer_science)" title="Tuple (computer science)" class="mw-redirect">Tuples</a></li>
</ul>
<h4><span class="mw-headline" id="Everything_is_an_expression">Everything is an expression</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=12" title="Edit section: Everything is an expression">edit</a><span class="mw-editsection-bracket">]</span></span></h4>
<table class="metadata plainlinks ambox ambox-content ambox-Unreferenced" role="presentation">
<tr>
<td class="mbox-image">
<div style="width:52px;"><a href="/wiki/File:Question_book-new.svg" class="image"><img alt="Question book-new.svg" src="//upload.wikimedia.org/wikipedia/en/thumb/9/99/Question_book-new.svg/50px-Question_book-new.svg.png" width="50" height="39" srcset="//upload.wikimedia.org/wikipedia/en/thumb/9/99/Question_book-new.svg/75px-Question_book-new.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/9/99/Question_book-new.svg/100px-Question_book-new.svg.png 2x" /></a></div>
</td>
<td class="mbox-text"><span class="mbox-text-span">This section <b>does not <a href="/wiki/Wikipedia:Citing_sources" title="Wikipedia:Citing sources">cite</a> any <a href="/wiki/Wikipedia:Verifiability" title="Wikipedia:Verifiability">references or sources</a></b>. <span class="hide-when-compact">Please help improve this section by <a href="/wiki/Help:Introduction_to_referencing/1" title="Help:Introduction to referencing/1">adding citations to reliable sources</a>. Unsourced material may be challenged and <a href="/wiki/Wikipedia:Verifiability#Burden_of_evidence" title="Wikipedia:Verifiability">removed</a>.</span> <small><i>(June 2013)</i></small></span></td>
</tr>
</table>
<p>Unlike C or Java, but similar to languages such as <a href="/wiki/Lisp_(programming_language)" title="Lisp (programming language)">Lisp</a>, Scala makes no distinction between statements and expressions. All statements are in fact expressions that evaluate to some value. Functions that would be declared as returning <code>void</code> in C or Java, and statements like <code>while</code> that logically do not return a value, are in Scala considered to return the type <code>Unit</code>, which is a <a href="/wiki/Singleton_(mathematics)" title="Singleton (mathematics)">singleton type</a>, with only one object of that type. Functions and operators that never return at all (e.g. the <code>throw</code> operator or a function that always exits <a href="/wiki/Exception_handling" title="Exception handling">non-locally</a> using an exception) logically have return type <code>Nothing</code>, a special type containing no objects that is a <a href="/wiki/Bottom_type" title="Bottom type">bottom type</a>, i.e. a subclass of every possible type. (This in turn makes type <code>Nothing</code> compatible with every type, allowing <a href="/wiki/Type_inference" title="Type inference">type inference</a> to function correctly.)</p>
<p>Similarly, an <code>if-then-else</code> "statement" is actually an expression, which produces a value, i.e. the result of evaluating one of the two branches. This means that such a block of code can be inserted wherever an expression is desired, obviating the need for a <a href="/wiki/Ternary_operator" title="Ternary operator" class="mw-redirect">ternary operator</a> in Scala:</p>
<table>
<tr>
<td>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="java source-java">
<pre class="de1">
<span class="co1">// Java:</span>
<span class="kw4">int</span> hexDigit <span class="sy0">=</span> x <span class="sy0">>=</span> <span class="nu0">10</span> <span class="sy0">?</span> x <span class="sy0">+</span> <span class="st0">'A'</span> <span class="sy0">-</span> <span class="nu0">10</span> <span class="sy0">:</span> x <span class="sy0">+</span> <span class="st0">'0'</span><span class="sy0">;</span>
</pre></div>
</div>
</td>
<td>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="scala source-scala">
<pre class="de1">
<span class="co1">// Scala:</span>
<span class="kw1">val</span> hexDigit <span class="sy0">=</span> <span class="kw1">if</span> <span class="br0">(</span>x <span class="sy0">>=</span> <span class="nu0">10</span><span class="br0">)</span> x + <span class="st0">'A'</span> - <span class="nu0">10</span> <span class="kw1">else</span> x + <span class="st0">'0'</span>
</pre></div>
</div>
</td>
</tr>
</table>
<p>For similar reasons, <code>return</code> statements are unnecessary in Scala, and in fact are discouraged. As in Lisp, the last expression in a block of code is the value of that block of code, and if the block of code is the body of a function, it will be returned by the function.</p>
<p>Note that a special syntax exists for functions returning <code>Unit</code>, which emphasizes the similarity between such functions and Java <code>void</code>-returning functions:</p>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="scala source-scala">
<pre class="de1">
<span class="kw1">def</span> printValue<span class="br0">(</span>x<span class="sy0">:</span> String<span class="br0">)</span> <span class="br0">{</span>
println<span class="br0">(</span><span class="st0">"I ate a %s"</span>.<span class="me1">format</span><span class="br0">(</span>x<span class="br0">)</span><span class="br0">)</span>
<span class="br0">}</span>
</pre></div>
</div>
<p>However, the function could equally well be written with explicit return value:</p>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="scala source-scala">
<pre class="de1">
<span class="kw1">def</span> printValue<span class="br0">(</span>x<span class="sy0">:</span> String<span class="br0">)</span><span class="sy0">:</span> Unit <span class="sy0">=</span> <span class="br0">{</span>
println<span class="br0">(</span><span class="st0">"I ate a %s"</span>.<span class="me1">format</span><span class="br0">(</span>x<span class="br0">)</span><span class="br0">)</span>
<span class="br0">}</span>
</pre></div>
</div>
<p>or equivalently (with type inference, and omitting the unnecessary braces):</p>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="scala source-scala">
<pre class="de1">
<span class="kw1">def</span> printValue<span class="br0">(</span>x<span class="sy0">:</span> String<span class="br0">)</span> <span class="sy0">=</span> println<span class="br0">(</span><span class="st0">"I ate a %s"</span>.<span class="me1">format</span><span class="br0">(</span>x<span class="br0">)</span><span class="br0">)</span>
</pre></div>
</div>
<h4><span class="mw-headline" id="Type_inference">Type inference</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=13" title="Edit section: Type inference">edit</a><span class="mw-editsection-bracket">]</span></span></h4>
<p>Due to <a href="/wiki/Type_inference" title="Type inference">type inference</a>, the type of variables, function return values, and many other expressions can typically be omitted, as the compiler can deduce it. Examples are <code>val x = "foo"</code> (for an immutable, <a href="/wiki/Constant_(programming)" title="Constant (programming)">constant</a> variable or <a href="/wiki/Immutable_object" title="Immutable object">immutable object</a>) or <code>var x = 1.5</code> (for a variable whose value can later be changed). Type inference in Scala is essentially local, in contrast to the more global <a href="/wiki/Hindley-Milner" title="Hindley-Milner" class="mw-redirect">Hindley-Milner</a> algorithm used in <a href="/wiki/Haskell_(programming_language)" title="Haskell (programming language)">Haskell</a>, <a href="/wiki/ML_(programming_language)" title="ML (programming language)">ML</a> and other more purely functional languages. This is done to facilitate object-oriented programming. The result is that certain types still need to be declared (most notably, function parameters, and the return types of <a href="/wiki/Recursion_(computer_science)" title="Recursion (computer science)">recursive functions</a>), e.g.</p>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="scala source-scala">
<pre class="de1">
<span class="kw1">def</span> formatApples<span class="br0">(</span>x<span class="sy0">:</span> Int<span class="br0">)</span> <span class="sy0">=</span> <span class="st0">"I ate %d apples"</span>.<span class="me1">format</span><span class="br0">(</span>x<span class="br0">)</span>
</pre></div>
</div>
<p>or (with a return type declared for a recursive function)</p>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="scala source-scala">
<pre class="de1">
<span class="kw1">def</span> factorial<span class="br0">(</span>x<span class="sy0">:</span> Int<span class="br0">)</span><span class="sy0">:</span> Int <span class="sy0">=</span>
<span class="kw1">if</span> <span class="br0">(</span>x <span class="sy0">==</span> <span class="nu0">0</span><span class="br0">)</span>
<span class="nu0">1</span>
<span class="kw1">else</span>
x<span class="sy0">*</span>factorial<span class="br0">(</span>x - <span class="nu0">1</span><span class="br0">)</span>
</pre></div>
</div>
<h4><span class="mw-headline" id="Anonymous_functions">Anonymous functions</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=14" title="Edit section: Anonymous functions">edit</a><span class="mw-editsection-bracket">]</span></span></h4>
<p>In Scala, functions are objects, and a convenient syntax exists for specifying <a href="/wiki/Anonymous_function" title="Anonymous function">anonymous functions</a>. An example is the expression <code>x => x < 2</code>, which specifies a function with a single parameter, that compares its argument to see if it is less than 2. It is equivalent to the Lisp form <code>(lambda (x) (< x 2))</code>. Note that neither the type of <code>x</code> nor the return type need be explicitly specified, and can generally be inferred by <a href="/wiki/Type_inference" title="Type inference">type inference</a>; but they can be explicitly specified, e.g. as <code>(x: Int) => x < 2</code> or even <code>(x: Int) => (x < 2): Boolean</code>.</p>
<p>Anonymous functions behave as true <a href="/wiki/Closure_(computer_science)" title="Closure (computer science)">closures</a> in that they automatically capture any variables that are lexically available in the environment of the enclosing function. Those variables will be available even after the enclosing function returns, and unlike in the case of Java's "anonymous inner classes" do not need to be declared as final. (It is even possible to modify such variables if they are mutable, and the modified value will be available the next time the anonymous function is called.)</p>
<p>An even shorter form of anonymous function uses <a href="/wiki/Free_variables_and_bound_variables" title="Free variables and bound variables">placeholder</a> variables: For example, the following:</p>
<dl>
<dd><code>list map { x => sqrt(x) }</code></dd>
</dl>
<p>can be written more concisely as</p>
<dl>
<dd><code>list map { sqrt(_) }</code></dd>
</dl>
<h4><span class="mw-headline" id="Immutability">Immutability</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=15" title="Edit section: Immutability">edit</a><span class="mw-editsection-bracket">]</span></span></h4>
<p>Scala enforces a distinction between immutable (unmodifiable, read-only) variables, whose value cannot be changed once assigned, and mutable variables, which can be changed. A similar distinction is made between immutable and mutable objects. The distinction must be made when a variable is declared: Immutable variables are declared with <code>val</code> while mutable variables use <code>var</code>. Similarly, all of the <a href="/wiki/Collection_(abstract_data_type)" title="Collection (abstract data type)">collection</a> objects (container types) in Scala, e.g. <a href="/wiki/Linked_list" title="Linked list">linked lists</a>, <a href="/wiki/Array_data_type" title="Array data type">arrays</a>, <a href="/wiki/Set_(computer_science)" title="Set (computer science)" class="mw-redirect">sets</a> and <a href="/wiki/Hash_table" title="Hash table">hash tables</a>, are available in mutable and immutable variants, with the immutable variant considered the more basic and default implementation. The immutable variants are <a href="/wiki/Persistent_data_structure" title="Persistent data structure">"persistent"</a> data types in that they create a new object that encloses the old object and adds the new member(s); this is similar to how linked lists are built up in Lisp, where elements are prepended by creating a new "cons" cell with a pointer to the new element (the "head") and the old list (the "tail"). Persistent structures of this sort essentially remember the entire history of operations and allow for very easy concurrency — no locks are needed as no shared objects are ever modified.</p>
<h4><span class="mw-headline" id="Lazy_.28non-strict.29_evaluation">Lazy (non-strict) evaluation</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=16" title="Edit section: Lazy (non-strict) evaluation">edit</a><span class="mw-editsection-bracket">]</span></span></h4>
<p>Evaluation is strict ("eager") by default. In other words, Scala evaluates expressions as soon as they are available, rather than as needed. However, you can declare a variable non-strict ("lazy") with the <code>lazy</code> keyword, meaning that the code to produce the variable's value will not be evaluated until the first time the variable is referenced. Non-strict collections of various types also exist (such as the type <code>Stream</code>, a non-strict linked list), and any collection can be made non-strict with the <code>view</code> method. Non-strict collections provide a good semantic fit to things like server-produced data, where the evaluation of the code to generate later elements of a list (that in turn triggers a request to a server, possibly located somewhere else on the web) only happens when the elements are actually needed.</p>
<h4><span class="mw-headline" id="Tail_recursion">Tail recursion</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=17" title="Edit section: Tail recursion">edit</a><span class="mw-editsection-bracket">]</span></span></h4>
<p>Functional programming languages commonly provide <a href="/wiki/Tail_call" title="Tail call">tail call</a> optimization to allow for extensive use of <a href="/wiki/Recursion_(computer_science)" title="Recursion (computer science)">recursion</a> without <a href="/wiki/Stack_overflow" title="Stack overflow">stack overflow</a> problems. Limitations in Java bytecode complicate tail call optimization on the JVM. In general, a function that calls itself with a tail call can be optimized, but mutually recursive functions cannot. <a href="/wiki/Trampoline_(computing)" title="Trampoline (computing)">Trampolines</a> have been suggested as a workaround.<sup id="cite_ref-23" class="reference"><a href="#cite_note-23"><span>[</span>23<span>]</span></a></sup> Trampoline support has been provided by the Scala library with the object <code>scala.util.control.TailCalls</code> since Scala 2.8.0 (released July 14, 2010).<sup id="cite_ref-24" class="reference"><a href="#cite_note-24"><span>[</span>24<span>]</span></a></sup></p>
<h4><span class="mw-headline" id="Case_classes_and_pattern_matching">Case classes and pattern matching</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=18" title="Edit section: Case classes and pattern matching">edit</a><span class="mw-editsection-bracket">]</span></span></h4>
<p>Scala has built-in support for <a href="/wiki/Pattern_matching" title="Pattern matching">pattern matching</a>, which can be thought as a more sophisticated, extensible version of a <a href="/wiki/Switch_statement" title="Switch statement">switch statement</a>, where arbitrary data types can be matched (rather than just simple types like integers, booleans and strings), including arbitrary nesting. A special type of class known as a <i>case class</i> is provided, which includes automatic support for pattern matching and can be used to model the <a href="/wiki/Algebraic_data_type" title="Algebraic data type">algebraic data types</a> used in many functional programming languages. (From the perspective of Scala, a case class is simply a normal class for which the compiler automatically adds certain behaviors that could also be provided manually—e.g. definitions of methods providing for deep comparisons and hashing, and destructuring a case class on its constructor parameters during pattern matching.)</p>
<p>An example of a definition of the <a href="/wiki/Quicksort" title="Quicksort">quicksort</a> algorithm using pattern matching is as follows:</p>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="scala source-scala">
<pre class="de1">
<span class="kw1">def</span> qsort<span class="br0">(</span>list<span class="sy0">:</span> List<span class="br0">[</span>Int<span class="br0">]</span><span class="br0">)</span><span class="sy0">:</span> List<span class="br0">[</span>Int<span class="br0">]</span> <span class="sy0">=</span> list <span class="kw1">match</span> <span class="br0">{</span>
<span class="kw1">case</span> Nil <span class="sy0">=></span> Nil
<span class="kw1">case</span> pivot <span class="sy0">::</span> tail <span class="sy0">=></span>
<span class="kw1">val</span> <span class="br0">(</span>smaller, rest<span class="br0">)</span> <span class="sy0">=</span> tail.<span class="me1">partition</span><span class="br0">(</span><span class="sy0">_</span> <span class="sy0"><</span> pivot<span class="br0">)</span>
qsort<span class="br0">(</span>smaller<span class="br0">)</span> <span class="sy0">:::</span> pivot <span class="sy0">::</span> qsort<span class="br0">(</span>rest<span class="br0">)</span>
<span class="br0">}</span>
</pre></div>
</div>
<p>The idea here is that we partition a list into the elements less than a pivot and the elements not less, recursively sort each part, and paste the results together with the pivot in between. This uses the same <a href="/wiki/Divide_and_conquer_algorithm" title="Divide and conquer algorithm">divide-and-conquer</a> strategy of <a href="/wiki/Mergesort" title="Mergesort" class="mw-redirect">mergesort</a> and other fast sorting algorithms.</p>
<p>The <code>match</code> operator is used to do pattern matching on the object stored in <code>list</code>. Each <code>case</code> expression is tried in turn to see if it will match, and the first match determines the result. In this case, <code>Nil</code> only matches the literal object <code>Nil</code>, but <code>pivot :: tail</code> matches a non-empty list, and simultaneously <i>destructures</i> the list according to the pattern given. In this case, the associated code will have access to a local variable named <code>pivot</code> holding the head of the list, and another variable <code>tail</code> holding the tail of the list. Note that these variables are read-only, and are semantically very similar to variable <a href="/wiki/Name_binding" title="Name binding">bindings</a> established using the <code>let</code> operator in Lisp and Scheme.</p>
<p>Pattern matching also happens in local variable declarations. In this case, the return value of the call to <code>tail.partition</code> is a <a href="/wiki/Tuple_(computer_science)" title="Tuple (computer science)" class="mw-redirect">tuple</a> — in this case, two lists. (Tuples differ from other types of containers, e.g. lists, in that they are always of fixed size and the elements can be of differing types — although here they are both the same.) Pattern matching is the easiest way of fetching the two parts of the tuple.</p>
<p>The form <code>_ < pivot</code> is a declaration of an <a href="/wiki/Anonymous_function" title="Anonymous function">anonymous function</a> with a placeholder variable; see the section above on anonymous functions.</p>
<p>The list operators <code>::</code> (which adds an element onto the beginning of a list, similar to <code>cons</code> in Lisp and Scheme) and <code>:::</code> (which appends two lists together, similar to <code>append</code> in Lisp and Scheme) both appear. Despite appearances, there is nothing "built-in" about either of these operators. As specified above, any string of symbols can serve as function name, and a method applied to an object can be written "<a href="/wiki/Infix" title="Infix">infix</a>"-style without the period or parentheses. The line above as written:</p>
<dl>
<dd>
<dl>
<dd><code>qsort(smaller) ::: pivot :: qsort(rest)</code></dd>
</dl>
</dd>
</dl>
<p>could also be written as follows:</p>
<dl>
<dd>
<dl>
<dd><code>qsort(rest).::(pivot).:::(qsort(smaller))</code></dd>
</dl>
</dd>
</dl>
<p>in more standard method-call notation. (Methods that end with a colon are right-associative and bind to the object to the right.)</p>
<h4><span class="mw-headline" id="Partial_functions">Partial functions</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=19" title="Edit section: Partial functions">edit</a><span class="mw-editsection-bracket">]</span></span></h4>
<p>In the pattern-matching example above, the body of the <code>match</code> operator is a <a href="/wiki/Partial_function" title="Partial function">partial function</a>, which consists of a series of <code>case</code> expressions, with the first matching expression prevailing, similar to the body of a <a href="/wiki/Switch_statement" title="Switch statement">switch statement</a>. Partial functions are also used in the exception-handling portion of a <code>try</code> statement:</p>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="scala source-scala">
<pre class="de1">
<span class="kw1">try</span> <span class="br0">{</span>
...
<span class="br0">}</span> <span class="kw1">catch</span> <span class="br0">{</span>
<span class="kw1">case</span> nfe<span class="sy0">:</span>NumberFormatException <span class="sy0">=></span> <span class="br0">{</span> println<span class="br0">(</span>nfe<span class="br0">)</span><span class="sy0">;</span> List<span class="br0">(</span><span class="nu0">0</span><span class="br0">)</span> <span class="br0">}</span>
<span class="kw1">case</span> <span class="sy0">_</span> <span class="sy0">=></span> Nil
<span class="br0">}</span>
</pre></div>
</div>
<p>Finally, a partial function can be used by itself, and the result of calling it is equivalent to doing a <code>match</code> over it. For example, the previous code for quicksort can be written as follows:</p>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="scala source-scala">
<pre class="de1">
<span class="kw1">val</span> qsort<span class="sy0">:</span> List<span class="br0">[</span>Int<span class="br0">]</span> <span class="sy0">=></span> List<span class="br0">[</span>Int<span class="br0">]</span> <span class="sy0">=</span> <span class="br0">{</span>
<span class="kw1">case</span> Nil <span class="sy0">=></span> Nil
<span class="kw1">case</span> pivot <span class="sy0">::</span> tail <span class="sy0">=></span>
<span class="kw1">val</span> <span class="br0">(</span>smaller, rest<span class="br0">)</span> <span class="sy0">=</span> tail.<span class="me1">partition</span><span class="br0">(</span><span class="sy0">_</span> <span class="sy0"><</span> pivot<span class="br0">)</span>
qsort<span class="br0">(</span>smaller<span class="br0">)</span> <span class="sy0">:::</span> pivot <span class="sy0">::</span> qsort<span class="br0">(</span>rest<span class="br0">)</span>
<span class="br0">}</span>
</pre></div>
</div>
<p>Here we declare a read-only <i>variable</i> whose type is a function from lists of integers to lists of integers, and bind it to a partial function. (Note that the single parameter of the partial function is never explicitly declared or named.) However, we can still call this variable exactly as if it were a normal function:</p>
<pre>
scala> qsort(List(6,2,5,9))
res32: List[Int] = List(2, 5, 6, 9)
</pre>
<h3><span class="mw-headline" id="Object-oriented_extensions">Object-oriented extensions</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=20" title="Edit section: Object-oriented extensions">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<p>Scala is a pure <a href="/wiki/Object-oriented_language" title="Object-oriented language" class="mw-redirect">object-oriented language</a> in the sense that every value is an <a href="/wiki/Object_(computer_science)" title="Object (computer science)">object</a>. <a href="/wiki/Data_type" title="Data type">Data types</a> and behaviors of objects are described by <a href="/wiki/Class_(computer_science)" title="Class (computer science)" class="mw-redirect">classes</a> and <a href="/wiki/Trait_(computer_science)" title="Trait (computer science)" class="mw-redirect">traits</a>. Class abstractions are extended by <a href="/wiki/Subclass_(computer_science)" title="Subclass (computer science)" class="mw-redirect">subclassing</a> and by a flexible <a href="/wiki/Mixin" title="Mixin">mixin</a>-based composition mechanism to avoid the problems of <a href="/wiki/Multiple_inheritance" title="Multiple inheritance">multiple inheritance</a>.</p>
<p>Traits are Scala's replacement for Java's <a href="/wiki/Protocol_(object-oriented_programming)" title="Protocol (object-oriented programming)">interfaces</a>. Interfaces in Java are highly restricted, able only to contain abstract function declarations. This has led to criticism that providing convenience methods in interfaces is awkward (the same methods must be reimplemented in every implementation), and extending a published interface in a backwards-compatible way is impossible. Traits are similar to <a href="/wiki/Mixin" title="Mixin">mixin</a> classes in that they have nearly all the power of a regular abstract class, lacking only class parameters (Scala's equivalent to Java's constructor parameters), since traits are always mixed in with a class. The <code>super</code> operator behaves specially in traits, allowing traits to be chained using composition in addition to inheritance. For example, consider a simple window system designed as follows:</p>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="scala source-scala">
<pre class="de1">
<span class="kw1">abstract</span> <span class="kw1">class</span> Window <span class="br0">{</span>
<span class="co1">// abstract</span>
<span class="kw1">def</span> draw<span class="br0">(</span><span class="br0">)</span>
<span class="br0">}</span>
<span class="kw1">class</span> SimpleWindow <span class="kw1">extends</span> Window <span class="br0">{</span>
<span class="kw1">def</span> draw<span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span>
println<span class="br0">(</span><span class="st0">"in SimpleWindow"</span><span class="br0">)</span>
<span class="co1">// draw a basic window</span>
<span class="br0">}</span>
<span class="br0">}</span>
<span class="kw1">trait</span> WindowDecoration <span class="kw1">extends</span> Window <span class="br0">{</span> <span class="br0">}</span>
<span class="kw1">trait</span> HorizontalScrollbarDecoration <span class="kw1">extends</span> WindowDecoration <span class="br0">{</span>
<span class="co1">// "abstract override" is needed here in order for "super()" to work because the parent</span>
<span class="co1">// function is abstract. If it were concrete, regular "override" would be enough.</span>
<span class="kw1">abstract</span> <span class="kw1">override</span> <span class="kw1">def</span> draw<span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span>
println<span class="br0">(</span><span class="st0">"in HorizontalScrollbarDecoration"</span><span class="br0">)</span>
<span class="kw1">super</span>.<span class="me1">draw</span><span class="br0">(</span><span class="br0">)</span>
<span class="co1">// now draw a horizontal scrollbar</span>
<span class="br0">}</span>
<span class="br0">}</span>
<span class="kw1">trait</span> VerticalScrollbarDecoration <span class="kw1">extends</span> WindowDecoration <span class="br0">{</span>
<span class="kw1">abstract</span> <span class="kw1">override</span> <span class="kw1">def</span> draw<span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span>
println<span class="br0">(</span><span class="st0">"in VerticalScrollbarDecoration"</span><span class="br0">)</span>
<span class="kw1">super</span>.<span class="me1">draw</span><span class="br0">(</span><span class="br0">)</span>
<span class="co1">// now draw a vertical scrollbar</span>
<span class="br0">}</span>
<span class="br0">}</span>
<span class="kw1">trait</span> TitleDecoration <span class="kw1">extends</span> WindowDecoration <span class="br0">{</span>
<span class="kw1">abstract</span> <span class="kw1">override</span> <span class="kw1">def</span> draw<span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span>
println<span class="br0">(</span><span class="st0">"in TitleDecoration"</span><span class="br0">)</span>
<span class="kw1">super</span>.<span class="me1">draw</span><span class="br0">(</span><span class="br0">)</span>
<span class="co1">// now draw the title bar</span>
<span class="br0">}</span>
<span class="br0">}</span>
</pre></div>
</div>
<p>You can then declare a variable as follows:</p>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="scala source-scala">
<pre class="de1">
<span class="kw1">val</span> mywin <span class="sy0">=</span> <span class="kw1">new</span> SimpleWindow <span class="kw1">with</span> VerticalScrollbarDecoration <span class="kw1">with</span> HorizontalScrollbarDecoration <span class="kw1">with</span> TitleDecoration
</pre></div>
</div>
<p>Then, the result of calling <code>mywin.draw()</code> will be</p>
<pre>
in TitleDecoration
in HorizontalScrollbarDecoration
in VerticalScrollbarDecoration
in SimpleWindow
</pre>
<p>In other words, the call to <code>draw</code> first executed the code in <code>TitleDecoration</code> (the last trait mixed in), then (through the <code>super()</code> calls) threaded back through the other mixed-in traits and eventually to the code in <code>Window</code> itself, <i>even though none of the traits inherited from one another</i>. This is similar to the Java <a href="/wiki/Decorator_pattern" title="Decorator pattern">decorator pattern</a> (e.g. as used in <a href="/wiki/Java_Platform,_Standard_Edition#java.io" title="Java Platform, Standard Edition">Java's I/O classes</a>), but is more concise and less error-prone, as it doesn't require explicitly encapsulating the parent window or explicitly forwarding functions whose implementation isn't changed. This <a href="/wiki/Design_pattern" title="Design pattern">design pattern</a> in Scala has been given the name <i>cake pattern</i>.</p>
<h3><span class="mw-headline" id="Expressive_type_system">Expressive type system</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=21" title="Edit section: Expressive type system">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<p>Scala is equipped with an expressive static type system that enforces the safe and coherent use of abstractions. In particular, the type system supports:</p>
<ul>
<li><a href="/wiki/Classes_(computer_science)" title="Classes (computer science)" class="mw-redirect">Classes</a> and <a href="/wiki/Abstract_type" title="Abstract type">abstract types</a> as object members</li>
<li>Structural types</li>
<li>Path-dependent types</li>
<li>Compound types</li>
<li>Explicitly typed self references</li>
<li><a href="/wiki/Generic_programming" title="Generic programming">Generic classes</a></li>
<li><a href="/wiki/Polymorphism_(computer_science)" title="Polymorphism (computer science)">Polymorphic</a> methods</li>
<li>Upper and lower type bounds</li>
<li><a href="/wiki/Variance_(computer_science)" title="Variance (computer science)" class="mw-redirect">Variance</a></li>
<li><a href="/wiki/Annotation" title="Annotation">Annotation</a></li>
<li>Views</li>
</ul>
<p>Scala is able to <a href="/wiki/Type_inference" title="Type inference">infer types</a> by usage. This makes most static type declarations optional. Static types need not be explicitly declared unless a compiler error indicates the need. In practice, some static type declarations are included for the sake of code clarity.</p>
<h3><span class="mw-headline" id="Type_enrichment">Type enrichment</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=22" title="Edit section: Type enrichment">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<p>A common technique in Scala, known as "enrich my library" (formerly "pimp my library",<sup id="cite_ref-artima1_22-1" class="reference"><a href="#cite_note-artima1-22"><span>[</span>22<span>]</span></a></sup> now discouraged due to its connotation), allows new methods to be used as if they were added to existing types. This is similar to the C# concept of <a href="/wiki/Extension_method" title="Extension method">extension methods</a> but more powerful, because the technique is not limited to adding methods and can for instance also be used to implement new interfaces. In Scala, this technique involves declaring an <a href="/wiki/Implicit_conversion" title="Implicit conversion" class="mw-redirect">implicit conversion</a> from the type "receiving" the method to a new type (typically, a class) that wraps the original type and provides the additional method. If a method cannot be found for a given type, the compiler automatically searches for any applicable implicit conversions to types that provide the method in question.</p>
<p>This technique allows new methods to be added to an existing class using an add-on library such that only code that <i>imports</i> the add-on library gets the new functionality, and all other code is unaffected.</p>
<p>The following example shows the enrichment of type <code>Int</code> with methods <code>isEven</code> and <code>isOdd</code>:</p>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="scala source-scala">
<pre class="de1">
<span class="kw1">object</span> MyExtensions <span class="br0">{</span>
<span class="kw1">implicit</span> <span class="kw1">class</span> IntPredicates<span class="br0">(</span>i<span class="sy0">:</span> Int<span class="br0">)</span> <span class="br0">{</span>
<span class="kw1">def</span> isEven <span class="sy0">=</span> i <span class="sy0">%</span> <span class="nu0">2</span> <span class="sy0">==</span> <span class="nu0">0</span>
<span class="kw1">def</span> isOdd <span class="sy0">=</span> <span class="sy0">!</span>isEven
<span class="br0">}</span>
<span class="br0">}</span>
<span class="kw1">import</span> MyExtensions.<span class="sy0">_</span> <span class="co1">// bring implicit enrichment into scope</span>
<span class="nu0">4</span>.<span class="me1">isEven</span> <span class="co1">// -> true</span>
</pre></div>
</div>
<p>Importing the members of <code>MyExtensions</code> brings the implicit conversion to extension class <code>IntPredicates</code> into scope.<sup id="cite_ref-25" class="reference"><a href="#cite_note-25"><span>[</span>25<span>]</span></a></sup></p>
<h2><span class="mw-headline" id="Concurrency">Concurrency</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=23" title="Edit section: Concurrency">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>Scala standard library includes support for the <a href="/wiki/Actor_model" title="Actor model">actor model</a>, in addition to the standard <a href="/wiki/Java_platform" title="Java platform" class="mw-redirect">Java</a> concurrency APIs. The company called <i>Typesafe</i> provides a stack<sup id="cite_ref-26" class="reference"><a href="#cite_note-26"><span>[</span>26<span>]</span></a></sup> that includes <a href="/wiki/Akka_(toolkit)" title="Akka (toolkit)">Akka</a>,<sup id="cite_ref-AkkaAbout_27-0" class="reference"><a href="#cite_note-AkkaAbout-27"><span>[</span>27<span>]</span></a></sup> a separate open source framework that provides actor-based concurrency. Akka actors may be <a href="/wiki/Distributed_computing" title="Distributed computing">distributed</a> or combined with <a href="/wiki/Software_transactional_memory" title="Software transactional memory">software transactional memory</a> ("transactors"). Alternative <a href="/wiki/Communicating_sequential_processes" title="Communicating sequential processes">CSP</a> implementations for channel-based message passing are Communicating Scala Objects,<sup id="cite_ref-CSO_28-0" class="reference"><a href="#cite_note-CSO-28"><span>[</span>28<span>]</span></a></sup> or simply via <a href="/wiki/JCSP" title="JCSP">JCSP</a>.</p>
<p>An Actor is like a thread instance with a mailbox. It can be created by system.actorOf, and using receive to get a message and ! to send a message.<sup id="cite_ref-29" class="reference"><a href="#cite_note-29"><span>[</span>29<span>]</span></a></sup> The following example shows an EchoServer which can receive messages and then print them.</p>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="scala source-scala">
<pre class="de1">
<span class="kw1">val</span> echoServer <span class="sy0">=</span> actor<span class="br0">(</span><span class="kw1">new</span> Act <span class="br0">{</span>
become <span class="br0">{</span>
<span class="kw1">case</span> msg <span class="sy0">=></span> println<span class="br0">(</span><span class="st0">"echo "</span> + msg<span class="br0">)</span>
<span class="br0">}</span>
<span class="br0">}</span><span class="br0">)</span>
echoServer <span class="sy0">!</span> <span class="st0">"hi"</span>
</pre></div>
</div>
<p>Scala also comes with built-in support for data-parallel programming in the form of Parallel Collections <sup id="cite_ref-30" class="reference"><a href="#cite_note-30"><span>[</span>30<span>]</span></a></sup> integrated into its Standard Library since the version 2.9.0.</p>
<p>The following example shows how to use Parallel Collections to improve performance.<sup id="cite_ref-31" class="reference"><a href="#cite_note-31"><span>[</span>31<span>]</span></a></sup></p>
<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
<div class="scala source-scala">
<pre class="de1">
<span class="kw1">val</span> urls <span class="sy0">=</span> List<span class="br0">(</span><span class="st0">"http://scala-lang.org"</span>, <span class="st0">"https://github.com/scala/scala"</span><span class="br0">)</span>
<span class="kw1">def</span> fromURL<span class="br0">(</span>url<span class="sy0">:</span> String<span class="br0">)</span> <span class="sy0">=</span> scala.<span class="me1">io</span>.<span class="me1">Source</span>.<span class="me1">fromURL</span><span class="br0">(</span>url<span class="br0">)</span>
.<span class="me1">getLines</span><span class="br0">(</span><span class="br0">)</span>.<span class="me1">mkString</span><span class="br0">(</span><span class="st0">"<span class="es1">\n</span>"</span><span class="br0">)</span>
<span class="kw1">val</span> t <span class="sy0">=</span> System.<span class="me1">currentTimeMillis</span><span class="br0">(</span><span class="br0">)</span>
urls.<span class="me1">par</span>.<span class="me1">map</span><span class="br0">(</span>fromURL<span class="br0">(</span><span class="sy0">_</span><span class="br0">)</span><span class="br0">)</span>
println<span class="br0">(</span><span class="st0">"time: "</span> + <span class="br0">(</span>System.<span class="me1">currentTimeMillis</span> - t<span class="br0">)</span> + <span class="st0">"ms"</span><span class="br0">)</span>
</pre></div>
</div>
<h2><span class="mw-headline" id="Testing">Testing</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=24" title="Edit section: Testing">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>There are several ways to test code in Scala:</p>
<ul>
<li><a rel="nofollow" class="external text" href="http://www.scalatest.org/">ScalaTest</a> supports multiple testing styles and can integrate with Java-based testing frameworks</li>
<li><a rel="nofollow" class="external text" href="https://github.com/rickynils/scalacheck">ScalaCheck</a>, a library similar to Haskell's <a href="/wiki/QuickCheck" title="QuickCheck">QuickCheck</a></li>
<li><a rel="nofollow" class="external text" href="http://specs2.org/">specs2</a>, a library for writing executable software specifications</li>
<li><a rel="nofollow" class="external text" href="http://scalamock.org/">ScalaMock</a> provides support for testing high-order and curried functions</li>
<li><a href="/wiki/JUnit" title="JUnit">JUnit</a> or <a href="/wiki/TestNG" title="TestNG">TestNG</a>, two popular testing frameworks written in Java</li>
<li><a href="/wiki/Jelastic" title="Jelastic">Jelastic</a> <a rel="nofollow" class="external autonumber" href="http://blog.jelastic.com/2013/07/08/getting-started-with-scala-sbt/">[1]</a>, a PaaS Platform compatible with Scala</li>
</ul>
<h2><span class="mw-headline" id="Versions">Versions</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=25" title="Edit section: Versions">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<table class="wikitable">
<tr>
<th scope="col">Version</th>
<th scope="col">Released</th>
<th scope="col">Features</th>
<th scope="col">Status</th>
<th scope="col">Notes</th>
</tr>
<tr>
<th scope="row"><a rel="nofollow" class="external text" href="http://www.scala-lang.org/download/changelog.html#2.">2.0</a></th>
<td>12-Mar-2006</td>
<td>_</td>
<td>_</td>
<td>_</td>
</tr>
<tr>
<th scope="row"><a rel="nofollow" class="external text" href="http://www.scala-lang.org/download/changelog.html#2.">2.1.8</a></th>
<td>23-Aug-2006</td>
<td>_</td>
<td>_</td>
<td>_</td>
</tr>
<tr>
<th scope="row"><a rel="nofollow" class="external text" href="http://www.scala-lang.org/download/changelog.html#2.">2.3.0</a></th>
<td>23-Nov-2006</td>
<td>_</td>
<td>_</td>
<td>_</td>
</tr>
<tr>
<th scope="row"><a rel="nofollow" class="external text" href="http://www.scala-lang.org/download/changelog.html#2.">2.4.0</a></th>
<td>09-Mar-2007</td>
<td>_</td>
<td>_</td>
<td>_</td>
</tr>
<tr>
<th scope="row"><a rel="nofollow" class="external text" href="http://www.scala-lang.org/download/changelog.html#2.">2.5.0</a></th>
<td>02-May-2007</td>
<td>_</td>
<td>_</td>
<td>_</td>
</tr>
<tr>
<th scope="row"><a rel="nofollow" class="external text" href="http://www.scala-lang.org/download/changelog.html#2.">2.6.0</a></th>
<td>27-Jul-2007</td>
<td>_</td>
<td>_</td>
<td>_</td>
</tr>
<tr>
<th scope="row"><a rel="nofollow" class="external text" href="http://www.scala-lang.org/download/changelog.html#2.">2.7.0</a></th>
<td>07-Feb-2008</td>
<td>_</td>
<td>_</td>
<td>_</td>
</tr>
<tr>
<th scope="row"><a rel="nofollow" class="external text" href="http://www.scala-lang.org/download/changelog.html#2.8.0">2.8.0</a></th>
<td>14-Jul-2010</td>
<td>Revision the common, uniform, and all-encompassing framework for collection types.</td>
<td>_</td>
<td>_</td>
</tr>
<tr>
<th scope="row"><a rel="nofollow" class="external text" href="http://www.scala-lang.org/download/changelog.html#2.9.0">2.9.0</a></th>
<td>12-May-2011</td>
<td>_</td>
<td>_</td>
<td>_</td>
</tr>
<tr>
<th scope="row"><a rel="nofollow" class="external text" href="http://www.scala-lang.org/download/changelog.html">2.10</a></th>
<td>04-Jan-2013</td>
<td>
<ul>
<li><a rel="nofollow" class="external text" href="http://docs.scala-lang.org/overviews/core/value-classes.html">Value Classes</a></li>
<li><a rel="nofollow" class="external text" href="http://docs.scala-lang.org/sips/pending/implicit-classes.html">Implicit Classes</a></li>
<li><a rel="nofollow" class="external text" href="http://docs.scala-lang.org/overviews/core/string-interpolation.html">String Interpolation</a></li>
<li><a rel="nofollow" class="external text" href="http://docs.scala-lang.org/overviews/core/futures.html">Futures and Promises</a></li>
<li><a rel="nofollow" class="external text" href="http://docs.scala-lang.org/sips/pending/type-dynamic.html">Dynamic and applyDynamic</a></li>
<li>Dependent method types: * def identity(x: AnyRef): x.type = x // the return type says we return exactly what we got</li>
<li>New ByteCode emitter based on ASM: Can target JDK 1.5, 1.6 and 1.7 / Emits 1.6 bytecode by default / Old 1.5 backend is deprecated</li>
<li>A new Pattern Matcher: rewritten from scratch to generate more robust code (no more exponential blow-up!) / code generation and analyses are now independent (the latter can be turned off with -Xno-patmat-analysis)</li>
<li>Scaladoc Improvements</li>
<li>Implicits (-implicits flag)</li>
<li>Diagrams (-diagrams flag, requires graphviz)</li>
<li>Groups (-groups)</li>
<li><a rel="nofollow" class="external text" href="http://docs.scala-lang.org/sips/pending/modularizing-language-features.html">Modularized Language features</a></li>
<li><a rel="nofollow" class="external text" href="http://docs.scala-lang.org/overviews/parallel-collections/overview.html">Parallel Collections</a> are now configurable with custom thread pools</li>
<li>Akka Actors now part of the distribution\\scala.actors have been deprecated and the akka implementation is now included in the distribution.</li>
<li>Performance Improvements: Faster inliner / Range#sum is now O(1)</li>
<li>Update of ForkJoin library</li>
<li>Fixes in immutable TreeSet/TreeMap</li>
<li>Improvements to PartialFunctions</li>
<li>Addition of ??? and NotImplementedError</li>
<li>Addition of IsTraversableOnce + IsTraversableLike type classes for extension methods</li>
<li>Deprecations and cleanup</li>
<li>Floating point and octal literal syntax deprecation</li>
<li>Removed scala.dbc</li>
</ul>
<p>Experimental features</p>
<ul>
<li><a rel="nofollow" class="external text" href="http://docs.scala-lang.org/overviews/reflection/overview.html">Scala Reflection</a></li>
<li><a rel="nofollow" class="external text" href="http://docs.scala-lang.org/overviews/macros/overview.html">Macros</a></li>
</ul>
</td>
<td>_</td>
<td>_</td>
</tr>
<tr>
<th scope="row"><a rel="nofollow" class="external text" href="http://www.scala-lang.org/news/2013/06/06/release-notes-v2.10.2.html">2.10.2</a></th>
<td>06-Jun-2013</td>
<td>_</td>
<td>Current</td>
<td>_</td>
</tr>
<tr>
<th scope="row"><a rel="nofollow" class="external text" href="http://www.scala-lang.org/news/2013/07/11/release-notes-v2.11.0-M4.html">2.11.0-M4</a></th>
<td>11-Jul-2013</td>
<td>_</td>
<td>_</td>
<td>Milestone 4 pre-release</td>
</tr>
</table>
<h2><span class="mw-headline" id="Comparison_with_other_JVM_languages">Comparison with other JVM languages</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=26" title="Edit section: Comparison with other JVM languages">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>Scala is often compared with <a href="/wiki/Groovy_(programming_language)" title="Groovy (programming language)">Groovy</a> and <a href="/wiki/Clojure" title="Clojure">Clojure</a>, two other programming languages also built on top of the JVM. Among the main differences are:</p>
<ol>
<li>Scala is <a href="/wiki/Statically_typed" title="Statically typed" class="mw-redirect">statically typed</a>, while both Groovy and Clojure are <a href="/wiki/Dynamically_typed" title="Dynamically typed" class="mw-redirect">dynamically typed</a>. This adds complexity in the type system but allows many errors to be caught at compile time that would otherwise only manifest at runtime, and tends to result in significantly faster execution. (Note, however, that current versions of both Groovy and Clojure allow for optional type annotations, and Java 7 adds an "invoke dynamic" byte code that should aid in the execution of dynamic languages on the JVM. Both features should decrease the running time of Groovy and Clojure.)</li>
<li>Compared with Groovy, Scala diverges more from Java in its fundamental design. The primary purpose of Groovy was to make Java programming easier and less verbose, while Scala (in addition to having the same goal) was designed from the ground up to allow for a <a href="/wiki/Functional_programming" title="Functional programming">functional programming</a> style in addition to <a href="/wiki/Object-oriented_programming" title="Object-oriented programming">object-oriented programming</a>, and introduces a number of more "cutting-edge" features from functional programming languages like <a href="/wiki/Haskell_(programming_language)" title="Haskell (programming language)">Haskell</a> that are not often seen in mainstream languages.</li>
<li>Compared with Clojure, Scala is less of an extreme transition for a Java programmer. Clojure inherits from <a href="/wiki/Lisp_(programming_language)" title="Lisp (programming language)">Lisp</a>, with the result that it has a radically different syntax from Java and has a strong emphasis on functional programming while de-emphasizing object-oriented programming. Scala, on the other hand, maintains most of Java's syntax and attempts to be agnostic between object-oriented and functional programming styles, allowing either or both according to the programmer's taste.</li>
</ol>
<h2><span class="mw-headline" id="Adoption">Adoption</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=27" title="Edit section: Adoption">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h3><span class="mw-headline" id="Language_rankings">Language rankings</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=28" title="Edit section: Language rankings">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<p>As of 2013, all <a href="/wiki/JVM" title="JVM" class="mw-redirect">JVM</a>-based derivatives (Scala/Groovy/Clojure) are significantly less popular than the original <a href="/wiki/Java_language" title="Java language" class="mw-redirect">Java language</a> itself which is usually ranked first or second <a rel="nofollow" class="external autonumber" href="http://sogrady-media.redmonk.com/sogrady/files/2013/02/lang-rank-Q113-big.png">[2]</a><a rel="nofollow" class="external autonumber" href="http://www.tiobe.com">[3]</a><a rel="nofollow" class="external autonumber" href="http://lang-index.sf.net">[4]</a>, and which is also simultaneously evolving over time.</p>
<div class="thumb tleft">
<div class="thumbinner" style="width:222px;"><a href="/wiki/File:TIOBE_Scala_Ranking.png" class="image"><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/d/d3/TIOBE_Scala_Ranking.png/220px-TIOBE_Scala_Ranking.png" width="220" height="115" class="thumbimage" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/d/d3/TIOBE_Scala_Ranking.png/330px-TIOBE_Scala_Ranking.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/d/d3/TIOBE_Scala_Ranking.png/440px-TIOBE_Scala_Ranking.png 2x" /></a>
<div class="thumbcaption">
<div class="magnify"><a href="/wiki/File:TIOBE_Scala_Ranking.png" class="internal" title="Enlarge"><img src="//bits.wikimedia.org/static-1.22wmf21/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div>
TIOBE Scala since 2006…2013‑06</div>
</div>
</div>
<p>As of March 2013, the <a href="/wiki/TIOBE_index" title="TIOBE index">TIOBE index</a><sup id="cite_ref-32" class="reference"><a href="#cite_note-32"><span>[</span>32<span>]</span></a></sup> of programming language popularity shows Scala at 31st place with 0.341% of programmer mindshare (as measured by internet search engine rankings and similar publication-counting), while it was below the top 50 threshold the year before. Scala is now in the neighborhood of <a href="/wiki/Scheme_(programming_language)" title="Scheme (programming language)">Scheme</a> (29th), <a href="/wiki/Prolog_(programming_language)" title="Prolog (programming language)" class="mw-redirect">Prolog</a> (34th), <a href="/wiki/Erlang_(programming_language)" title="Erlang (programming language)">Erlang</a> (33rd) and <a href="/wiki/Haskell_(programming_language)" title="Haskell (programming language)">Haskell</a> (32nd). As of March 2013, Scala was well ahead<sup class="noprint Inline-Template" style="white-space:nowrap;">[<i><a href="/wiki/Wikipedia:Vagueness" title="Wikipedia:Vagueness"><span title="You can help — (September 2013)">vague</span></a></i>]</sup> of both <a href="/wiki/Groovy_(programming_language)" title="Groovy (programming language)">Groovy</a> and <a href="/wiki/Clojure" title="Clojure">Clojure</a>, the other two JVM-based languages that Scala is often compared with, both of which fall below 50th place. However, as of September 2013, the <a href="/wiki/TIOBE_index" title="TIOBE index">TIOBE index</a> placed Groovy at 21st (up at least thirty positions in the ranking), and Scala at 33rd. Similarly, the <a rel="nofollow" class="external text" href="http://lang-index.sourceforge.net/">Transparent Language Popularity Index</a> puts Scala at position 34, after Haskell and ahead of ML and Erlang.</p>
<p>Using another measure, as of February 2013 Scala placed 15th in terms of number of github projects, and 16th in terms of number of questions tagged on <a href="/wiki/Stack_Overflow" title="Stack Overflow">Stack Overflow</a>.<a rel="nofollow" class="external autonumber" href="http://sogrady-media.redmonk.com/sogrady/files/2013/02/lang-rank-Q113-big.png">[5]</a> (Groovy was 22nd place according to both of those statistics at that time; Clojure was 23rd and 24th, respectively.)<a rel="nofollow" class="external autonumber" href="http://sogrady-media.redmonk.com/sogrady/files/2013/02/lang-rank-Q113-big.png">[6]</a> The <a rel="nofollow" class="external text" href="http://redmonk.com/sogrady/2012/09/12/language-rankings-9-12/">RedMonk Programming Language Rankings</a> (which make use of popularity in <a href="/wiki/Stack_Overflow" title="Stack Overflow">Stack Overflow</a> and <a href="/wiki/GitHub" title="GitHub">GitHub</a>) show Scala clearly behind a first-tier group of 11 languages (including <a href="/wiki/Java_(programming_language)" title="Java (programming language)">Java</a>, <a href="/wiki/C_(programming_language)" title="C (programming language)">C</a>, <a href="/wiki/Python_(programming_language)" title="Python (programming language)">Python</a>, <a href="/wiki/PHP" title="PHP">PHP</a>, <a href="/wiki/Ruby_(programming_language)" title="Ruby (programming language)">Ruby</a>, etc.), but leading a second-tier group, ahead of Haskell, Groovy, Clojure, Erlang, Prolog, Scheme and Smalltalk.</p>
<p>According to <a href="/wiki/Indeed.com" title="Indeed.com">Indeed.com</a> Job Trends, Scala demand has been <a rel="nofollow" class="external text" href="http://www.indeed.com/trendgraph/jobgraph.png?q=scala&relative=1">rapidly increasing</a> since 2010, trending ahead of <a href="/wiki/Clojure" title="Clojure">Clojure</a> but behind <a href="/wiki/Groovy_(programming_language)" title="Groovy (programming language)">Groovy</a>.</p>
<p><br style="clear:both;" /></p>
<h3><span class="mw-headline" id="Companies">Companies</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Scala_(programming_language)&action=edit&section=29" title="Edit section: Companies">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<p>Many existing companies who depend on Java for business-critical applications are turning to Scala to boost their development and improve productivity, application scalability and reliability.</p>
<table class="wikitable">
<tr>
<th colspan="4">Website online</th>
<th colspan="4">Back office</th>
</tr>
<tr>
<td><a rel="nofollow" class="external text" href="http://www.scala-lang.org/node/1658#AppJet">AppJet</a></td>
<td><span class="flagicon"><a href="/wiki/Australia" title="Australia"><img alt="Australia" src="//upload.wikimedia.org/wikipedia/en/thumb/b/b9/Flag_of_Australia.svg/23px-Flag_of_Australia.svg.png" width="23" height="12" class="thumbborder" srcset="//upload.wikimedia.org/wikipedia/en/thumb/b/b9/Flag_of_Australia.svg/35px-Flag_of_Australia.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/b/b9/Flag_of_Australia.svg/46px-Flag_of_Australia.svg.png 2x" /></a></span><a href="/wiki/Atlassian" title="Atlassian">Atlassian</a><sup id="cite_ref-33" class="reference"><a href="#cite_note-33"><span>[</span>33<span>]</span></a></sup></td>
<td><span class="flagicon"><a href="/wiki/United_States" title="United States"><img alt="United States" src="//upload.wikimedia.org/wikipedia/en/thumb/a/a4/Flag_of_the_United_States.svg/23px-Flag_of_the_United_States.svg.png" width="23" height="12" class="thumbborder" srcset="//upload.wikimedia.org/wikipedia/en/thumb/a/a4/Flag_of_the_United_States.svg/35px-Flag_of_the_United_States.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/a/a4/Flag_of_the_United_States.svg/46px-Flag_of_the_United_States.svg.png 2x" /></a></span><a href="/wiki/Cisco_Systems" title="Cisco Systems">Cisco Systems</a></td>
<td><span class="flagicon"><a href="/wiki/United_States" title="United States"><img alt="United States" src="//upload.wikimedia.org/wikipedia/en/thumb/a/a4/Flag_of_the_United_States.svg/23px-Flag_of_the_United_States.svg.png" width="23" height="12" class="thumbborder" srcset="//upload.wikimedia.org/wikipedia/en/thumb/a/a4/Flag_of_the_United_States.svg/35px-Flag_of_the_United_States.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/a/a4/Flag_of_the_United_States.svg/46px-Flag_of_the_United_States.svg.png 2x" /></a></span>Cloudify</td>
<td><span class="flagicon"><a href="/wiki/United_States" title="United States"><img alt="United States" src="//upload.wikimedia.org/wikipedia/en/thumb/a/a4/Flag_of_the_United_States.svg/23px-Flag_of_the_United_States.svg.png" width="23" height="12" class="thumbborder" srcset="//upload.wikimedia.org/wikipedia/en/thumb/a/a4/Flag_of_the_United_States.svg/35px-Flag_of_the_United_States.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/a/a4/Flag_of_the_United_States.svg/46px-Flag_of_the_United_States.svg.png 2x" /></a></span><a href="/wiki/Amazon.com" title="Amazon.com">Amazon.com</a></td>
<td><span class="flagicon"><a href="/wiki/United_States" title="United States"><img alt="United States" src="//upload.wikimedia.org/wikipedia/en/thumb/a/a4/Flag_of_the_United_States.svg/23px-Flag_of_the_United_States.svg.png" width="23" height="12" class="thumbborder" srcset="//upload.wikimedia.org/wikipedia/en/thumb/a/a4/Flag_of_the_United_States.svg/35px-Flag_of_the_United_States.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/a/a4/Flag_of_the_United_States.svg/46px-Flag_of_the_United_States.svg.png 2x" /></a></span><a href="/wiki/Autodesk" title="Autodesk">Autodesk</a> Inc</td>
<td><span class="flagicon"><a href="/wiki/United_Kingdom" title="United Kingdom"><img alt="United Kingdom" src="//upload.wikimedia.org/wikipedia/en/thumb/a/ae/Flag_of_the_United_Kingdom.svg/23px-Flag_of_the_United_Kingdom.svg.png" width="23" height="12" class="thumbborder" srcset="//upload.wikimedia.org/wikipedia/en/thumb/a/ae/Flag_of_the_United_Kingdom.svg/35px-Flag_of_the_United_Kingdom.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/a/ae/Flag_of_the_United_Kingdom.svg/46px-Flag_of_the_United_Kingdom.svg.png 2x" /></a></span><br />
<a rel="nofollow" class="external text" href="http://cakesolutions.net/">Cake Solutions</a></td>
<td><span class="flagicon"><a href="/wiki/Switzerland" title="Switzerland"><img alt="Switzerland" src="//upload.wikimedia.org/wikipedia/commons/thumb/f/f3/Flag_of_Switzerland.svg/16px-Flag_of_Switzerland.svg.png" width="16" height="16" class="thumbborder" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/f/f3/Flag_of_Switzerland.svg/24px-Flag_of_Switzerland.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/f/f3/Flag_of_Switzerland.svg/32px-Flag_of_Switzerland.svg.png 2x" /></a></span><a href="/wiki/Credit_Suisse" title="Credit Suisse">Credit Suisse</a></td>
</tr>
<tr>
<td><span class="flagicon"><a href="/wiki/Switzerland" title="Switzerland"><img alt="Switzerland" src="//upload.wikimedia.org/wikipedia/commons/thumb/f/f3/Flag_of_Switzerland.svg/16px-Flag_of_Switzerland.svg.png" width="16" height="16" class="thumbborder" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/f/f3/Flag_of_Switzerland.svg/24px-Flag_of_Switzerland.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/f/f3/Flag_of_Switzerland.svg/32px-Flag_of_Switzerland.svg.png 2x" /></a></span><a rel="nofollow" class="external text" href="http://crossing-tech.com/">Crossing-Tech SA</a></td>
<td><span class="flagicon"><a href="/wiki/United_States" title="United States"><img alt="United States" src="//upload.wikimedia.org/wikipedia/en/thumb/a/a4/Flag_of_the_United_States.svg/23px-Flag_of_the_United_States.svg.png" width="23" height="12" class="thumbborder" srcset="//upload.wikimedia.org/wikipedia/en/thumb/a/a4/Flag_of_the_United_States.svg/35px-Flag_of_the_United_States.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/a/a4/Flag_of_the_United_States.svg/46px-Flag_of_the_United_States.svg.png 2x" /></a></span><a href="/wiki/EBay" title="EBay">eBay Inc.</a><sup id="cite_ref-34" class="reference"><a href="#cite_note-34"><span>[</span>34<span>]</span></a></sup></td>
<td>…</td>
<td><span class="flagicon"><a href="/wiki/Netherlands" title="Netherlands"><img alt="Netherlands" src="//upload.wikimedia.org/wikipedia/commons/thumb/2/20/Flag_of_the_Netherlands.svg/23px-Flag_of_the_Netherlands.svg.png" width="23" height="15" class="thumbborder" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/2/20/Flag_of_the_Netherlands.svg/35px-Flag_of_the_Netherlands.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/2/20/Flag_of_the_Netherlands.svg/45px-Flag_of_the_Netherlands.svg.png 2x" /></a></span>Elmar Reizen bv</td>
<td><span class="flagicon"><a href="/wiki/Netherlands" title="Netherlands"><img alt="Netherlands" src="//upload.wikimedia.org/wikipedia/commons/thumb/2/20/Flag_of_the_Netherlands.svg/23px-Flag_of_the_Netherlands.svg.png" width="23" height="15" class="thumbborder" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/2/20/Flag_of_the_Netherlands.svg/35px-Flag_of_the_Netherlands.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/2/20/Flag_of_the_Netherlands.svg/45px-Flag_of_the_Netherlands.svg.png 2x" /></a></span><a href="/wiki/Computer_Sciences_Corporation" title="Computer Sciences Corporation">CSC</a><sup id="cite_ref-35" class="reference"><a href="#cite_note-35"><span>[</span>35<span>]</span></a></sup></td>
<td><span class="flagicon"><a href="/wiki/France" title="France"><img alt="France" src="//upload.wikimedia.org/wikipedia/en/thumb/c/c3/Flag_of_France.svg/23px-Flag_of_France.svg.png" width="23" height="15" class="thumbborder" srcset="//upload.wikimedia.org/wikipedia/en/thumb/c/c3/Flag_of_France.svg/35px-Flag_of_France.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/c/c3/Flag_of_France.svg/45px-Flag_of_France.svg.png 2x" /></a></span><br />