blob: d81f6e001ab7f678307ea29d73b5ea3137874ba2 (
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
43
44
45
46
47
48
49
50
51
52
|
discard """
file: "tvariantstack.nim"
output: "came here"
"""
#BUG
type
TAnyKind = enum
nkInt,
nkFloat,
nkString
PAny = ref TAny
TAny = object
case kind: TAnyKind
of nkInt: intVal: int
of nkFloat: floatVal: float
of nkString: strVal: string
TStack* = object
list*: seq[TAny]
proc newStack(): TStack =
result.list = @[]
proc push(Stack: var TStack, item: TAny) =
var nSeq: seq[TAny] = @[item]
for i in items(Stack.list):
nSeq.add(i)
Stack.list = nSeq
proc pop(Stack: var TStack): TAny =
result = Stack.list[0]
Stack.list.delete(0)
var stack = newStack()
var s: TAny
s.kind = nkString
s.strVal = "test"
stack.push(s)
var nr: TAny
nr.kind = nkint
nr.intVal = 78
stack.push(nr)
var t = stack.pop()
echo "came here"
|