summary refs log tree commit diff stats
path: root/tests/misc/tvarious1.nim
blob: 9c0b541dbf4781e48abd613dbc6e1a6550c1ba25 (plain) (blame)
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
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-
discard """
output: '''
1
0
Whopie
12
1.7'''
"""

echo len([1_000_000]) #OUT 1

type
  TArray = array[0..3, int]
  TVector = distinct array[0..3, int]
proc `[]`(v: TVector; idx: int): int = TArray(v)[idx]
var v: TVector
echo v[2]

# bug #569

import deques

type
  TWidget = object
    names: Deque[string]

var w = TWidget(names: initDeque[string]())

addLast(w.names, "Whopie")

for n in w.names: echo(n)

# bug #681

type TSomeRange = object
  hour: range[0..23]

var value: string
var val12 = TSomeRange(hour: 12)

value = $(if val12.hour > 12: val12.hour - 12 else: val12.hour)
echo value

# bug #1334

var ys = @[4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2]
#var x = int(ys.high / 2) #echo ys[x] # Works
echo ys[int(ys.high / 2)] # Doesn't work
class="p">) else: result = n when false: let it = detectForLoopVar(body) if it == nil: error("no for loop in body", body) let v = newTree(nnkVarSection, newTree(nnkIdentDefs, res, newTree(nnkBracketExpr, bindSym"seq", newCall(bindSym"type", body)), newEmptyNode())) result = newTree(nnkStmtListExpr, v, t(body, res), res) #echo repr result let stuff = collect: var i = -1 while i < 4: inc i for it in data: if it < 5 and it > 1: it echo stuff echo collect(for i in 0..3: i)