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
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using System.Runtime.InteropServices; | |
| namespace nim_sharp | |
| { | |
| [StructLayout(LayoutKind.Sequential)] |
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
| # Hello world program | |
| type | |
| Implies[A, B] = proc(a: A): B | |
| # example Propositions | |
| type | |
| X = object | |
| Y = object | |
| Z = object |
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 | |
| DenseMatrixLayout* {.pure.} = enum | |
| ColumnMajor, | |
| RowMajor | |
| DenseMatrix*[R, C: static[int], T; L: static[DenseMatrixLayout]] = object | |
| elements: array[R*C, T] | |
| Matrix4 = DenseMatrix[4, 4, float, DenseMatrixLayout.ColumnMajor] |
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 | |
| Matrix[Rows, Cols: static[int]; E] = generic M | |
| M.T is T | |
| Rows == M.M | |
| Cols == M.N | |
| m[range[0..(R - 1)], range[0..(C - 1)]] is T | |
| proc foo(m: Matrix) = | |
| echo Matrix.M, m.N | |
| let x = Matrix.E() |
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
| int MakeGetRequest(const TCHAR* server, const TCHAR* url, string& out) | |
| { | |
| auto inet = InternetOpen(_T("AdRotate"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, 0, 0); | |
| if(inet == NULL) | |
| return 1; | |
| auto session = InternetConnect(inet, server, 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, NULL); | |
| if(session == NULL) | |
| return 2; |
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
| const htmlElements = ["a", "div", "head"] | |
| for e in htmlElements: | |
| template (e) (body) = | |
| echo "<" & e & ">" | |
| body | |
| echo "</" & e & ">" | |
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 | |
| V[T; I: static[int]] = array[0..I, T] | |
| proc foo(x: V): V.T = | |
| result = x[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
| const NULL* = 0 | |
| type | |
| TagPtr = distinct int | |
| Sum2[T1,T2] = TagPtr | |
| proc copyHeap*[T](x: var T): ptr T = | |
| var |
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 ast, parser | |
| {.pragma: libnim, exportc: "nim_$1", dynlib, cdecl.} | |
| proc parse(code: cstring): int {.libnim.} = | |
| var n = parseString($code) | |
| return ord(n != nil) | |
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
| # my alternative grammar is build around blocks as the most prominent syntax element: | |
| # foo [anything] means foo do(anything): | |
| # ... ... | |
| # | |
| # foo is foo: | |
| # ... ... | |
| # | |
| # Then we have "match" magic/macro that looks like this: | |
| match expr # The compiler automatically looks for a field used in a case |