2.scala控制结构、函数、异常处理
2.scala控制结构、函数、异常处理---小书匠,在线编辑器,MARKDOWN,Evernote,文件版本
a:focus {
outline: thin dotted #333;
outline: 5px auto -webkit-focus-ring-color;
outline-offset: -2px;
}
a:hover,
a:active {
outline: 0;
}
a {
color: #0088cc;
text-decoration: none;
}
a:hover {
color: #005580;
text-decoration: underline;
}
p {
margin: 0 0 1.1em;
}
small {
font-size: 85%;
}
strong {
font-weight: bold;
}
em {
font-style: italic;
}
cite {
font-style: normal;
}
h1.story_title {
margin: 0.7em 0;
}
.story_tags {
margin: 0 0 1.2em;
}
h1,
h2,
h3,
h4,
h5,
h6 {
margin: 0.5em 0;
margin: 1.0em 0 .6em 0;
font-family: inherit;
font-weight: 500;
line-height: 20px;
color: inherit;
text-rendering: optimizelegibility;
}
h1,
h2,
h3 {
line-height: 40px;
}
h1 {
font-size: 38.5px;
}
h2 {
font-size: 31.5px;
}
h3 {
font-size: 24.5px;
}
h4 {
font-size: 17.5px;
}
h5 {
font-size: 14px;
}
h6 {
font-size: 11.9px;
}
ul,
ol {
padding: 0;
margin: 0 0 10px 35px;
}
ul ul,
ul ol,
ol ol,
ol ul {
margin-bottom: 0;
}
dl {
margin-bottom: 20px;
}
dt,
dd {
line-height: 20px;
}
dt {
font-weight: bold;
}
dd {
margin-left: 10px;
}
hr {
margin: 20px 0;
border: 0;
border-top: 1px solid #eeeeee;
border-bottom: 1px solid #ffffff;
}
abbr[title],
abbr[data-original-title] {
cursor: help;
border-bottom: 1px dotted #999999;
}
blockquote {
padding: 0 0 0 15px;
margin: 0 0 20px;
border-left: 5px solid #dddddd;
}
blockquote p {
margin-bottom: 0;
font-size: 16px;
font-weight: 300;
line-height: 25px;
}
blockquote small {
display: block;
line-height: 20px;
color: #999999;
}
blockquote small:before {
content: '\2014 \00A0';
}
q:before,
q:after,
blockquote:before,
blockquote:after {
content: "";
}
address {
display: block;
margin-bottom: 20px;
font-style: normal;
line-height: 20px;
}
img {
height: auto;
max-width: 100%;
vertical-align: middle;
border: 0;
}
table {
max-width: 100%;
background-color: transparent;
border-collapse: collapse;
border-spacing: 0;
border: 1px solid rgba(34,36,38,.15);
}
.tag.label{
display: inline-block;
vertical-align: baseline;
line-height: 1;
margin: 0em 0.125em;
background-color: #e8e8e8;
border-color: #e8e8e8;
background-image: none;
padding: 0.6em 0.8em;
color: rgba(0, 0, 0, 0.6);
text-transform: none;
font-weight: bold;
border-radius: 0.2857rem;
box-sizing: border-box;
font-size: 0.7428rem;
}
.table {
width: 100%;
margin-bottom: 20px;
}
.table th,
.table td {
padding: 8px;
line-height: 20px;
text-align: left;
vertical-align: top;
border-top: 1px solid #dddddd;
}
.table th {
font-weight: bold;
}
.table thead th {
vertical-align: bottom;
}
.table caption + thead tr:first-child th,
.table caption + thead tr:first-child td,
.table colgroup + thead tr:first-child th,
.table colgroup + thead tr:first-child td,
.table thead:first-child tr:first-child th,
.table thead:first-child tr:first-child td {
border-top: 0;
}
.table tbody + tbody {
border-top: 2px solid #dddddd;
}
.table .table {
background-color: #ffffff;
}
.table-striped tbody > tr:nth-child(odd) > td,
.table-striped tbody > tr:nth-child(odd) > th {
background-color: #f9f9f9;
}
.table-celled.table tr td,.table-celled.table tr th {
border-left: 1px solid rgba(34,36,38,.1)
}
.table-celled.table tr td:first-child,.table-celled.table tr th:first-child {
border-left: none
}
.toc ul {
list-style: none;
}
p {
line-height: 1.6;
}
body>p {
margin-bottom: 1.8em;
}
body>p>img.center,
body>p>a>img.center {
display: block;
margin: 0 auto;
background-color: rgba(128,128,128,0.3);
}
body {
font-family: 'Helvetica Neue', Helvetica, Tahoma, Arial, 'Hiragino Sans GB', STHeiti, "Microsoft YaHei", "微软雅黑", 'WenQuanYi Micro Hei', STXihei, "华文细黑", Heiti, "黑体", SimSun, "宋体", Song, sans-serif;
font-size: 1.15em;
font-weight: 100;
// line-height: 1.8em;
color: #2f2f2f;
}
em.cjk_emphasis{
font-style: normal;
font-family: Georgia,"Times New Roman",Times,"楷体","AR PL UKai CN", "NSimSun","Songti SC","SimSun",serif!important;
}
body dt,
body dd {
line-height: 1.35em;
}
body code, body .xiaoshujiang_code {
// background-color: #D6DBDF;
border: 0;
border-radius: 4px;
// color: #2C3E50;
font-size: 90%;
// padding: 2px 4px;
}
code {
background-color: #D6DBDF;
border-radius: 4px;
color: #2C3E50;
padding: 2px 4px;
}
.xiaoshujiang_code ol{
margin-bottom: 0px;
}
body h1 {
line-height: 1.6;
}
body h2 {
line-hieght: 1.1;
}
body h3 {
line-height: 1.1;
}
/**
* Treeview syntax highlighting based on highlight.js
* Copyright (c) 2014-2015, Asciidocfx Team, (MIT Licensed)
* https://github.com/asciidocfx/highlight-treeview.js
*/
.language-treeview.hljs{
position: relative;
}
.hljs-folder,
.hljs-hiddenfile,
.hljs-file {
position: relative;
vertical-align: top;
display: inline-block;
height: 16px;
}
.hljs-folder:before,
.hljs-file:before,
.hljs-hiddenfile:before {
top: 0;
content: '';
width: 14px;
height: 12px;
margin-top: 0px;
margin-right: 3px;
position: relative;
display: inline-block;
background-size: 14px;
background-repeat: no-repeat;
}
.hljs-file:before,
.hljs-hiddenfile:before {
height: 14px;
margin-left: 1px;
}
.hljs-hiddenfile {
opacity: 0.6;
}
.hljs-file.photo:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c5";
}
.hljs-file.plain:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f016";
}
.hljs-file.source:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c9";
}
.hljs-file.archive:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c6";
}
.hljs-file.audio:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c7";
}
.hljs-file.video:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c8";
}
.hljs-file.pdf:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c1";
}
.hljs-file.xls:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c3";
}
.hljs-file.doc:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c2";
}
.hljs-file.ppt:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c4";
}
.hljs-folder:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f114";
}
.hljs-hiddenfile:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f016";
}
.hljs-tvline {
margin-left: 6px;
position: absolute;
text-indent: -99em;
padding-bottom: 8px;
vertical-align: top;
display: inline-block;
border-left-width: 1px;
border-left-style: solid;
border-left-color: rgb(94, 144, 117);
}
.hljs-folder-branch {
width: 8px;
height: 8px;
margin-top: -1px;
margin-left: 6px;
text-indent: -99em;
position: relative;
vertical-align: top;
display: inline-block;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: rgb(94, 144, 117);
}
.hljs-folder-branch.win {
width: 14px;
margin-right: 2px;
}
.hljs-folder-last-branch {
height: 7px;
width: 7px;
margin-left: 6px;
text-indent: -99em;
position: relative;
vertical-align: top;
display: inline-block;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: rgb(94, 144, 117);
border-left-width: 1px;
border-left-style: solid;
border-left-color: rgb(94, 144, 117);
}
.hljs-folder-last-branch.win {
width: 13px;
margin-right: 2px;
}
/**
* Treeview syntax highlighting based on highlight.js
*/
.mark{
border: 0;
background-color: #ddf3e7;
border-radius: 4px;
color: #29754d;
font-size: 90%;
padding: 2px 4px;
}
.line_mark{
border: 1px dashed #3A4C42;
}
code .mark, .xiaoshujiang_code .mark{
border-radius: 0px;
font-size: initial;
padding: initial;
}
a.attachment{
background-color: #ecf0f3;
border: 1px solid #bec6cb;
display: inline-block;
padding: 5px;
margin: 2px;
min-width: 250px;
}
a.attachment i.fa{
font-size: 3em;
float: left;
margin-right: 0.2em;
}
a.attachment .filename{
vertical-align: top;
text-align: left;
font-weight: bold;
}
a.attachment .filesize{
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
opacity: .6;
font-size: 80%;
white-space: nowrap;
}
.checkbox .checked{
text-decoration: line-through;
}
.flow-chart, .sequence-diagram{
text-align: center;
}
.plot, .plot-image{
text-align: center;
min-height: 200px;
min-width: 200px;
}
pre, .xiaoshujiang_pre {
line-height: initial !important;
word-wrap: break-word;
word-break: break-word;
}
.xiaoshujiang_code_container pre{
margin: 0px;
}
.xiaoshujiang_code_container.xiaoshujiang_code_chunk{
box-shadow: 0 0 0 1px #A3C293 inset,0 0 0 0 transparent;
margin: 1em 0;
padding: 1em;
}
.xiaoshujiang_code_container.xiaoshujiang_code_chunk_hide_code{
box-shadow: initial;
padding: initial;
padding-bottom: 2em;
}
.xiaoshujiang_code_container .out_put{
box-shadow: 0 0 0 1px #A3C293 inset,0 0 0 0 transparent;
margin: 1em 0;
background-color: #FCFFF5;
color: #2C662D;
padding: 1em;
}
.xiaoshujiang_code_container .out_put_error{
background-color: #FFF6F6;
color: #9F3A38;
margin: 1em 0;
box-shadow: 0 0 0 1px #E0B4B4 inset,0 0 0 0 transparent;
padding: 1em;
}
.xiaoshujiang_pre {
font-family: monospace;
white-space: pre;
}
.story_align_left, .story_align_left .story_image_container {
text-align: left;
}
.story_align_right, .story_align_right .story_image_container {
text-align: right;
}
.story_align_center, .story_align_center .story_image_container {
text-align: center;
}
.story_align_justify, .story_align_justify .story_image_container {
text-align: justify;
}
/**
* code line nums
*/
code.hljs.code_linenums, .xiaoshujiang_code.hljs.code_linenums{
position: relative;
}
.ol_linenums{
padding: 0px;
margin-left: 30px;
border-left: 1px solid #e0e0e0;
}
.li_linenum{
line-height: 20px;
margin-left: 10px;
list-style: none;
counter-increment: lines 1;
}
.li_linenum.li_list_style{
list-style: inherit;
margin-left: 5px;
}
.li_linenum:before, .li_linenum_before_span{
content: counter(lines, decimal);
position: absolute;
left: 0px;
text-align: center;
width: 2.5em;
opacity: 0.5;
vertical-align: top;
}
.li_linenum_before_span_hide{
display: none;
}
.xiaoshujiang_code .code_line_break_hack{
margin:0;
border:0;
border-top:0;
border-bottom:0;
}
/**
* code line nums
*/
.mathjax-container{
text-align: center;
}
div.mathjax{
max-width: 700px;
margin: 0 auto;
font-size: 14px;
}
text{
font-size: 14px;
}
/**
* block image
*/
.story_image_container{
text-align: center;
}
.story_image_container>.story_image{
display: inline-block;
position: relative;
max-width: 80%;
}
.story_image_caption{
border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 10px;
}
.story_image_blank_caption{
border-bottom: 0px;
}
/**
.story_image:before, .story_image:after{
content: '';
position: absolute;
z-index: -2;
bottom: 13px;
left: 10px;
width: 50%;
height: 20%;
border-radius: 10px/90px;
box-shadow: 0 15px 10px rgba(0,0,0,0.7);
-webkit-transform: rotate(-3deg);
-moz-transform: rotate(-3deg);
-ms-transform: rotate(-3deg);
-o-transform: rotate(-3deg);
transform: rotate(-3deg);
}
.story_image:after {
right: 10px;
left: auto;
-webkit-transform: rotate(3deg);
-moz-transform: rotate(3deg);
-ms-transform: rotate(3deg);
-o-transform: rotate(3deg);
transform: rotate(3deg);
}
**/
.story_image>img{
border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);
}
.story_inline_image>img{
max-width: 50%;
vertical-align: bottom;
}
.story_remote_resource_block{
text-align: center;
}
.xiaoshujiang_code_container {
margin: 1em 0px;
position: relative;
padding-bottom: 2em;
}
.xiaoshujiang_code_title_container{
font-size: 70%;
opacity: 0.5;
}
.xiaoshujiang_code_title_container>.xiaoshujiang_code_infos{
float: right;
}
.task-list-item{
list-style: none;
}
.task-list-item>input{
margin: 0 0 0 -20px;
}
.video_container{
width: 100%;
display: table;
text-align: center;
position: relative;
padding-bottom: 56.25%!important;
}
.slideshare_container .inner{
position: relative;
width: 100%;
}
.slideshare_container .inner iframe{
width: 100%;
height: 100%;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.video_container iframe{
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 1;
vertical-align: middle;
}
kbd{
display: inline-block;
padding: 3px 5px;
font-size: 11px;
line-height: 10px;
color: #555;
vertical-align: middle;
background-color: #fcfcfc;
border: solid 1px #ccc;
border-bottom-color: #bbb;
border-radius: 3px;
box-shadow: inset 0 -1px 0 #bbb;
}
.blank_anchor_id {
float: left;
}
.blank_anchor_id {
visibility: hidden;
}
.blank_anchor_id:before {
content: 'a';
}
blockquote footer{
margin: 1em 0;
font-style: italic;
}
blockquote footer cite {
margin: 0 1em;
}
/*wavedrom start*/
.wavedrom_svg text, .wavedrom_svg_defs text {
font-size:11pt;
font-style:normal;
font-variant:normal;
font-weight:normal;
font-stretch:normal;
text-align:center;
fill-opacity:1;
font-family:Helvetica
}
.wavedrom_svg .muted, .wavedrom_svg_defs .muted {
fill:#aaa
}
.wavedrom_svg .warning, .wavedrom_svg_defs .warning {
fill:#f6b900
}
.wavedrom_svg .error, .wavedrom_svg_defs .error {
fill:#f60000
}
.wavedrom_svg .info, .wavedrom_svg_defs .info {
fill:#0041c4
}
.wavedrom_svg .success, .wavedrom_svg_defs .success {
fill:#00ab00
}
.wavedrom_svg .h1, .wavedrom_svg_defs .h1 {
font-size:33pt;
font-weight:bold
}
.wavedrom_svg .h2, .wavedrom_svg_defs .h2 {
font-size:27pt;
font-weight:bold
}
.wavedrom_svg .h3, .wavedrom_svg_defs .h3 {
font-size:20pt;
font-weight:bold
}
.wavedrom_svg .h4, .wavedrom_svg_defs .h4 {
font-size:14pt;
font-weight:bold
}
.wavedrom_svg .h5, .wavedrom_svg_defs .h5 {
font-size:11pt;
font-weight:bold
}
.wavedrom_svg .h6, .wavedrom_svg_defs .h6 {
font-size:8pt;
font-weight:bold
}
.wavedrom_svg_defs .s1 {
fill:none;
stroke:#000;
stroke-width:1;
stroke-linecap:round;
stroke-linejoin:miter;
stroke-miterlimit:4;
stroke-opacity:1;
stroke-dasharray:none
}
.wavedrom_svg_defs .s2 {
fill:none;
stroke:#000;
stroke-width:0.5;
stroke-linecap:round;
stroke-linejoin:miter;
stroke-miterlimit:4;
stroke-opacity:1;
stroke-dasharray:none
}
.wavedrom_svg_defs .s3 {
color:#000;
fill:none;
stroke:#000;
stroke-width:1;
stroke-linecap:round;
stroke-linejoin:miter;
stroke-miterlimit:4;
stroke-opacity:1;
stroke-dasharray:1,3;
stroke-dashoffset:0;
marker:none;
visibility:visible;
display:inline;
overflow:visible;
enable-background:accumulate
}
.wavedrom_svg_defs .s4 {
color:#000;
fill:none;
stroke:#000;
stroke-width:1;
stroke-linecap:round;
stroke-linejoin:miter;
stroke-miterlimit:4;
stroke-opacity:1;
stroke-dasharray:none;
stroke-dashoffset:0;
marker:none;
visibility:visible;
display:inline;
overflow:visible
}
.wavedrom_svg_defs .s5 {
fill:#fff;
stroke:none
}
.wavedrom_svg_defs .s6 {
color:#000;
fill:#ffffb4;
fill-opacity:1;
fill-rule:nonzero;
stroke:none;
stroke-width:1px;
marker:none;
visibility:visible;
display:inline;
overflow:visible;
enable-background:accumulate
}
.wavedrom_svg_defs .s7 {
color:#000;
fill:#ffe0b9;
fill-opacity:1;
fill-rule:nonzero;
stroke:none;
stroke-width:1px;
marker:none;
visibility:visible;
display:inline;
overflow:visible;
enable-background:accumulate
}
.wavedrom_svg_defs .s8 {
color:#000;
fill:#b9e0ff;
fill-opacity:1;
fill-rule:nonzero;
stroke:none;
stroke-width:1px;
marker:none;
visibility:visible;
display:inline;
overflow:visible;
enable-background:accumulate
}
.wavedrom_svg_defs .s9 {
fill:#000;
fill-opacity:1;
stroke:none
}
.wavedrom_svg_defs .s10 {
color:#000;
fill:#fff;
fill-opacity:1;
fill-rule:nonzero;
stroke:none;
stroke-width:1px;
marker:none;
visibility:visible;
display:inline;
overflow:visible;
enable-background:accumulate
}
.wavedrom_svg_defs .s11 {
fill:#0041c4;
fill-opacity:1;
stroke:none
}
.wavedrom_svg_defs .s12 {
fill:none;
stroke:#0041c4;
stroke-width:1;
stroke-linecap:round;
stroke-linejoin:miter;
stroke-miterlimit:4;
stroke-opacity:1;
stroke-dasharray:none
}
/*wavedrom stop*/
/*
Orginal Style from ethanschoonover.com/solarized (c) Jeremy Hull
*/
.hljs {
display: block;
overflow-x: auto;
padding: 0.5em;
background: #fdf6e3;
color: #657b83;
-webkit-text-size-adjust: none;
}
.hljs-comment,
.diff .hljs-header,
.hljs-doctype,
.hljs-pi,
.lisp .hljs-string,
.hljs-javadoc {
color: #93a1a1;
}
/* Solarized Green */
.hljs-keyword,
.hljs-winutils,
.method,
.hljs-addition,
.css .hljs-tag,
.hljs-request,
.hljs-status,
.nginx .hljs-title {
color: #859900;
}
/* Solarized Cyan */
.hljs-number,
.hljs-command,
.hljs-string,
.hljs-tag .hljs-value,
.hljs-rule .hljs-value,
.hljs-phpdoc,
.hljs-dartdoc,
.tex .hljs-formula,
.hljs-regexp,
.hljs-hexcolor,
.hljs-link_url {
color: #2aa198;
}
/* Solarized Blue */
.hljs-title,
.hljs-localvars,
.hljs-chunk,
.hljs-decorator,
.hljs-built_in,
.hljs-identifier,
.vhdl .hljs-literal,
.hljs-id,
.css .hljs-function,
.hljs-name {
color: #268bd2;
}
/* Solarized Yellow */
.hljs-attribute,
.hljs-variable,
.lisp .hljs-body,
.smalltalk .hljs-number,
.hljs-constant,
.hljs-class .hljs-title,
.hljs-parent,
.hljs-type,
.hljs-link_reference {
color: #b58900;
}
/* Solarized Orange */
.hljs-preprocessor,
.hljs-preprocessor .hljs-keyword,
.hljs-pragma,
.hljs-shebang,
.hljs-symbol,
.hljs-symbol .hljs-string,
.diff .hljs-change,
.hljs-special,
.hljs-attr_selector,
.hljs-subst,
.hljs-cdata,
.css .hljs-pseudo,
.hljs-header {
color: #cb4b16;
}
/* Solarized Red */
.hljs-deletion,
.hljs-important {
color: #dc322f;
}
/* Solarized Violet */
.hljs-link_label {
color: #6c71c4;
}
.tex .hljs-formula {
background: #eee8d5;
}
2.scala控制结构、函数、异常处理
2.1条件表达式
(1)if表达式有返回值,如val result = if(x>0) 0 else -1 ,则result值可能为0或-1
(2)if表达式分支语句返回值的类型不一致时,则表达式返回值的类型是它们共同的父类型Any
val result = if(x>0) 0 else "error"
则result的类型为Any
(3)若if表达式没有分支满足条件,则返回Unit
2.2块表达式
(1)块表达式的值是最后一个语句的返回值,一个块中有多个语句时用逗号隔开。如:
val result = {val x=2;val y=3;pow(x,y)}
2.3循环
(1)while循环的实现方式和java中一样。
(2)scala中的for循环写法如下:
for(i <- 1 to 10){ println(i) }
(3)for推导式。如果for循环的循环体以yield开始,则该循环会构造出一个集合,每次迭代生成集合中的一个值,如:
for(i <- 1 to 10) yield i%3 //得到Vector(1,2,0,1,2,0,1,2,0,1)
2.4函数
一个函数包含了函数名称,参数和函数体等三个元素,如:
def abs(x:Double) = if(x>=0) x else -x
如果不是递归函数,不需要给定返回值类型
2.5参数
(1)默认参数。调用某些函数时可以不用给出参数,此时使用默认参数。如:
def check(path:String,name:String="home")
使用check("local")时传入的两个参数分别为local和默认的home
(2)带名参数。在提供参数值的时候指定参数名,带名参数可以打乱参数列表的顺序,但是带名参数和不带名参数共同使用时,需要将不带名参数放在带名参数之前。
(3)变长参数。参数列表可以为同类型的多个参数。如:
def sum(num:Int*)={ val count = 0 for(i <-num){ count +=i } }
函数得到的是一个序列,但是不代表可以传入一个序列。如sum(1 to 5)这种写法是错误的。
2.6懒值
当val被生命为lazy时,它的初始化会被推迟,直到其被第一次取值时。如:
val a = 0 lazy val b = a*10
2.7异常处理
scala中异常处理与java类似。一般写法如下:
try{ process }catch{ case e:Throwable => some process case _ => other process }finally{ }
2.scala控制结构、函数、异常处理的更多相关文章
- Scala 控制结构
Scala内建的控制结构屈指可数,仅有if, while, for, match, try和函数调用而已. 几乎所有的Scala控制结构都会产生某个值(while和 do while虽然不能产生有意义 ...
- scala控制结构
#判断 scala> def min(x:Int,y:Int):Int={ var a=x if(x>y) a=y return a } scala> min(1,2)res1: I ...
- scala匿名函数
package com.ming.test import scala.math._ object AnonymousFunc { def valueAtOneQuarter(f:(Double)=&g ...
- Scala应用函数
我们使用“_” 来代替单个的参数,实际上你也可以使用“_”来代替整个参数列表,比如说,你可以使用 print _ 来代替 println (_). someNumbers.foreach(printl ...
- Scala 匿名函数
Scala 中定义匿名函数的语法很简单,箭头左边是参数列表,右边是函数体. 使用匿名函数后,我们的代码变得更简洁了. 下面的表达式就定义了一个接受一个Int类型输入参数的匿名函数: var inc = ...
- web前端学习(四)JavaScript学习笔记部分(3)-- JavaScript函数+异常处理+事件处理
1.Javascript函数-了解函数的用途 1.1.函数: 函数是由事件驱动的或者当它被调用时执行的可重复使用的代码块 2.Javascript函数-定义函数 2.1.function必须小写 3. ...
- python高阶函数&异常处理
高阶函数 1.什么是高阶函数 在Python中,变量可以指向函数 函数名也是变量 既然变量可以指向函数,函数的参数能接收变量,那么一个函数就可以接收另一个函数作为参数,这种函数就称之为高阶函数. ma ...
- Python函数&异常处理
1. 函数基础 1.1 参数和返回值 1.1.1 参数 位置参数.关键字参数 def my_func1(x, y, z): print(x+y+z, "计算结束") my_func ...
- Scala学习——函数高级操作
scala函数高级操作 一.字符串高级操作 多行字符串和插值 package top.ruandb.scala.Course06 object StringApp { def main(args: A ...
随机推荐
- Oracle的聚合函数group by结合CUBE和ROLLUP的使用
转自:https://docs.oracle.com/cd/E11882_01/server.112/e25554/aggreg.htm#DWHSG8618 CUBE Syntax CUBE appe ...
- vs2008 怎么在Release下调试代码
vs2008 怎么在Release下调试代码 (适用VS2005/VS2008) 在当前工程点击右键选择properties,选择 All Configurations C++>General- ...
- 全局安装了express框架,但是无法使用express指令的问题
错误截图: 产生这个错误的原因是:我安装的是express4版本,需要安装express-generator才能使用express命令 将express-generator安装后就都解决了:
- OracleUNDO
UNDO作用 数据的回滚 一致性读 表的闪回(事务,查询的闪回....) 失败会话的恢复 数据的回滚 SQL> rollback; 回滚的过程就是从回滚段里拿到刚刚执行的这条语句产生的回滚,然后 ...
- jquery slibings选取同级其他元素
jquery选取同级其他元素可以使用slibings方法,end方法可以清除之前的链式操作,相当于重新开始. <script type="text/javascript"&g ...
- Storm-源码分析-Topology Submit-Executor
在worker中通过executor/mk-executor worker e, 创建每个executor (defn mk-executor [worker executor-id] (let [e ...
- 第09章—使用Lombok插件
spring boot 系列学习记录:http://www.cnblogs.com/jinxiaohang/p/8111057.html 码云源码地址:https://gitee.com/jinxia ...
- Andrew Ng机器学习编程作业:Support Vector Machines
作业: machine-learning-ex6 1. 支持向量机(Support Vector Machines) 在这节,我们将使用支持向量机来处理二维数据.通过实验将会帮助我们获得一个直观感受S ...
- 对ASIHTTPRequest的封装
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/quanqinayng/article/details/37659751 .h文件 // // Ht ...
- Cpython支持的进程与线程(Day33)
一.multiprocessing模块介绍 python中的多线程无法利用CPU资源,在python中大部分情况使用多进程.python中提供了非常好的多进程包multiprocessing. mul ...