Skip to content

Instantly share code, notes, and snippets.

@zah
zah / transitive_implication.nim
Last active August 26, 2015 11:14
Proof-carrying Nim
# Hello world program
type
Implies[A, B] = proc(a: A): B
# example Propositions
type
X = object
Y = object
Z = object
@zah
zah / gist:9463398
Created March 10, 2014 11:31
implicit generics, vector
type
V[T; I: static[int]] = array[0..I, T]
proc foo(x: V): V.T =
result = x[0]
const htmlElements = ["a", "div", "head"]
for e in htmlElements:
template (e) (body) =
echo "<" & e & ">"
body
echo "</" & e & ">"
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;
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()
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]
#define HTTP_STATUS_CODES(_) \
_(200, OK) \
_(404, NOT_FOUND) \
_(505, INTERNAL_ERROR)
enum StatusCodes {
#define GENERATE_ENUM(CODE, MSG) MSG = CODE,
HTTP_STATUS_CODES(GENERATE_ENUM)
}
@zah
zah / gist:1140235
Created August 11, 2011 17:25
Nimrod ctags config
--langdef=nimrod
--langmap=nimrod:.nim
--regex-nimrod=/(\w+)\*?\s*=\s*object/\1/c,Class/
--regex-nimrod=/proc\s+(\w+)/\1/m,Procedure/
--regex-nimrod=/proc\s+`([^`]+)`/\1/o,Operator/
proc testConcat(a: string, b: string): string {.compileTime pure.} =
return a & b
const X = testConcat("test", "me")
proc test =
when len(X) > 2:
echo "big"
else:
echo "small"
@zah
zah / gist:1173554
Created August 26, 2011 14:41
Type associations in Nimrod
type 3DSpace = ...
type Plane = ...
type Line = ...
proc SpaceSplitterType(p: Place) : Line
proc SpaceSplitterType(p: 3DSpace) : Plane
# This is a generic algorithm that should work both in 2D and 3D context
proc ComputeProjection[S](space: S) =
# instantiate the correct space splitter type (needed for the algorithm)