File: 07-Variant.md

package info (click to toggle)
storm-lang 0.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,028 kB
  • sloc: ansic: 261,471; cpp: 140,432; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (27 lines) | stat: -rw-r--r-- 950 bytes parent folder | download | duplicates (2)
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
Variant
=======

The standard library contains the type [stormname:core.Variant] that represents an object of any
type in the system. Due to the need to accommodate any type, it has to allocate values on the heap
rather than internally. This means that using a `Variant` incurs a performance penalty over
situations where the types are known statically.

The `Variant` has no facility to extract the current value in a safe manner. It is necessary to use
[weak casts](md:/Language_Reference/Basic_Storm/Code/Type_Conversions) to extract the contained
type.

The `Variant` contains constructors that automatically cast any types into a `Variant`
implicitly. This allows functions that accept `Variant`s to be used conveniently.

Apart from the constructors, the `Variant` has the following members:

```stormdoc
@core.Variant
- .__init()
- .empty()
- .any()
- .has(*)
- .type()
```

It is also possible to print variants using `<<` or `toS` as usual.