-
Notifications
You must be signed in to change notification settings - Fork 11
/
call.nim
43 lines (34 loc) · 792 Bytes
/
call.nim
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
proc no_args() =
discard
# call
no_args()
proc fixed_args(x, y: int) =
echo x
echo y
# calls
fixed_args(1, 2) # x=1, y=2
fixed_args 1, 2 # same call
1.fixed_args(2) # same call
proc opt_args(x=1.0) =
echo x
# calls
opt_args() # 1
opt_args(3.141) # 3.141
proc var_args(v: varargs[string, `$`]) =
for x in v: echo x
# calls
var_args(1, 2, 3) # (1, 2, 3)
var_args(1, (2,3)) # (1, (2, 3))
var_args() # ()
## Named arguments
fixed_args(y=2, x=1) # x=1, y=2
## As a statement
if true:
no_args()
proc return_something(x: int): int =
x + 1
var a = return_something(2)
## First-class within an expression
let x = return_something(19) + 10
let y = 19.return_something() + 10
let z = 19.return_something + 10