Fix optarg() and added two more tests.
One for 'do notation' in a single function in an expression, another the trick of using the method call syntax to pass two parameters.
This commit is contained in:
parent
db031e2b47
commit
300c0376b5
1 changed files with 9 additions and 3 deletions
|
|
@ -1,9 +1,11 @@
|
||||||
discard """
|
discard """
|
||||||
output: '''140
|
output: '''140
|
||||||
5-120'''
|
5-120-120
|
||||||
|
359'''
|
||||||
"""
|
"""
|
||||||
|
import math
|
||||||
|
|
||||||
proc optarg(x:int):int = x
|
proc optarg(x:int, y:int = 0):int = x + 3 * y
|
||||||
proc singlearg(x:int):int = 20*x
|
proc singlearg(x:int):int = 20*x
|
||||||
echo optarg 1, singlearg 2
|
echo optarg 1, singlearg 2
|
||||||
|
|
||||||
|
|
@ -13,5 +15,9 @@ proc foo(x, y: int): int = x-y
|
||||||
|
|
||||||
let x = optarg foo 7.foo
|
let x = optarg foo 7.foo
|
||||||
let y = singlearg foo(1, foo 8)
|
let y = singlearg foo(1, foo 8)
|
||||||
|
let z = singlearg 1.foo foo 8
|
||||||
|
|
||||||
echo x, y
|
echo x, y, z
|
||||||
|
|
||||||
|
let a = [2,4,8].map do (d:int) -> int: d + 1
|
||||||
|
echo a[0], a[1], a[2]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue