/
call-by-name-parameters.js
42 lines (32 loc) · 1.45 KB
/
call-by-name-parameters.js
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
import Skb from 'components/skb-page'
export const id = "call-by-name-parameters"
export const title = "Scala Call-by-name Parameters"
export const date = "2020-08-07T17:01:43"
const scastieId = "XkgpvxRaQdSnfdO2yWuSOg"
const mainInfoBox = <>
<p>There are two ways to give parameters to a function in most programming languages: 'by-value' and 'call-by-name'.</p>
<p>The 'by-value' way is what we have seen in previous SKBs when we used functions and methods.</p>
<p>In this SKB, focus your attention on the way the parameters of the function are being declared and the syntax, notice anything?</p>
</>
const detailedInfoBox = <>
<p>Did you notice the <code>=> Int</code> in the parameter list?</p>
<p>You can understand it as if it was <code>() => Int</code>, meaning a function that will return <code>Int</code> when called.</p>
<p>The content of the parameter will not be evaluated until needed. Be aware that it will be re-evaluated for each time it is called. But we will look into it into a more advanced SKB later on.</p>
</>
const description = "Scala Knowledge Bits - Scala Call-by-name - Periodic exercise to learn bits of knowledge about Scala. Scala Call-by-name here."
const prevUrl = "list-filter-method"
const nextUrl = "case-class"
export const pageData = {
id,
title,
date,
scastieId,
mainInfoBox,
detailedInfoBox,
description,
prevUrl,
nextUrl
}
export default function Page() {
return <Skb lesson={pageData} />
}