Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,11 @@
proc `^`*[T: SomeInteger](base, exp: T): T =
var (base, exp) = (base, exp)
result = 1
while exp != 0:
if (exp and 1) != 0:
result *= base
exp = exp shr 1
base *= base
echo 2 ^ 10 # 1024

View file

@ -0,0 +1,6 @@
when defined windows:
echo "Call some Windows specific functions here"
elif defined linux:
echo "Call some Linux specific functions here"
else:
echo "Code for the other platforms"

View file

@ -0,0 +1,2 @@
static:
echo "Hello Compile time world: ", 2 ^ 10

View file

@ -0,0 +1 @@
const x = 2 ^ 10

View file

@ -0,0 +1,14 @@
import os
const debug = false
proc expensive: string =
sleep(milsecs = 100)
result = "That was difficult"
proc log(msg: string) =
if debug:
echo msg
for i in 1..10:
log expensive()

View file

@ -0,0 +1,6 @@
template log(msg: string) =
if debug:
echo msg
for i in 1..10:
log expensive()

View file

@ -0,0 +1,7 @@
template times(x, y: untyped): untyped =
for i in 1..x:
y
10.times: # or times 10: or times(10):
echo "hi"
echo "bye"

View file

@ -0,0 +1,15 @@
template optLog1{a and a}(a): auto = a
template optLog2{a and (b or (not b))}(a,b): auto = a
template optLog3{a and not a}(a: int): auto = 0
var
x = 12
s = x and x
# Hint: optLog1(x) --> x [Pattern]
r = (x and x) and ((s or s) or (not (s or s)))
# Hint: optLog2(x and x, s or s) --> x and x [Pattern]
# Hint: optLog1(x) --> x [Pattern]
q = (s and not x) and not (s and not x)
# Hint: optLog3(s and not x) --> 0 [Pattern]

View file

@ -0,0 +1,13 @@
import macros
dumpTree:
if x:
if y:
p0
else:
p1
else:
if y:
p2
else:
p3