This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # this works ########################## | |
| type | |
| Foo[N: static[int], T] = object | |
| elements: array[0..(N - 1), T] | |
| var f2 = Foo[2, float](elements: [1.0, 2.0]) | |
| var f3 = Foo[3, float](elements: [1.0, 2.0, 3.0]) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # compiles | |
| type Foo = tuple[x, y: float] | |
| proc foo(a, b: Foo): bool = (a.x == b.x) and (a.y == b.y) | |
| var f = (1.0, 2.0) | |
| check(foo(f, f)) | |
| # does not compile | |
| type Bar[T] = tuple[x, y: T] | |
| proc bar(a, b: Bar): bool = (a.x == b.x) and (a.y == b.y) # Error: undeclared identifier: 'x' | |
| var b = (1.0, 2.0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Suppose we have the following type for a rectangular array: | |
| type | |
| RectArray*[R, C: static[int], T] = distinct array[R * C, T] | |
| var a23: RectArray[2, 3, int] | |
| var a32: RectArray[3, 2, int] | |
| echo "a23: ", a23.R, "x", a23.C | |
| echo "a32: ", a32.R, "x", a32.C |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type | |
| RectArray*[R, C: static[int], T] = distinct array[R * C, T] | |
| StaticMatrix*[R, C: static[int], T] = object | |
| elements*: RectArray[R, C, T] | |
| StaticVector*[N: static[int], T] = StaticMatrix[N, 1, T] | |
| proc foo*[N, T](a: StaticVector[N, T]): T = 0.T |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| framework | |
| packageA | |
| bin | |
| docs | |
| src | |
| module1.nim | |
| module2.nim | |
| module3.nim | |
| tests | |
| tmodule1.nim |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import macros | |
| macro midlInterface*(head: expr; body: stmt): stmt {.immediate.} = | |
| ## Generates the glue code required for MIDL interface types. | |
| ## | |
| ## For example, the following declaration... | |
| ## | |
| ## midlInterface IUnknown: | |
| ## proc queryInterface*(riid: Iid; outObj: ptr pointer): HResult |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type | |
| Foo[T] = concept x, y | |
| foo(x, y) is bool | |
| Bar[T] = object | |
| b: T | |
| when true: # the following works | |
| proc foo(x, y: Bar): bool = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import macros | |
| const nmax = 500 | |
| type | |
| Complex*[T] = object | |
| re*: T | |
| im*: T | |
| converter toComplex*[T](x: tuple[re, im: T]): Complex[T] = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type IntArray[T; N: static[int]] = array[N, T] | |
| proc ones[T](N: static[int]): IntArray[T, N] = | |
| for i in 0 .. < N: | |
| result[i] = 1 | |
| echo @[ones[int](5)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type | |
| Foo[T] = ref object | |
| x: T | |
| Bar[N: static[int], T] = ref object | |
| a: array[N, T] | |
| x: T | |
| Foobar[N: static[int], T] = object | |
| b: Bar[N, T] |
OlderNewer