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
xclip –selection clipboard –t image/png (or jpg if it is available) –o > /tmp/nameofyourfile.png |
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
# Module A | |
var | |
x*, y: int | |
proc `*` *(a, b: seq[int]): seq[int] = | |
# allocate a new sequence: | |
newSeq(result, len(a)) | |
# multiply two int sequences: | |
for i in 0..len(a)-1: result[i] = a[i] * b[i] |
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 with enum | |
type | |
Direction = enum | |
north, east, south, west | |
var x = south # `x` is of type `Direction`; its value is `south` | |
echo x # writes "south" to `stdout` | |
#Subrange | |
type |
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
var | |
myBool = true | |
myCharacter = 'n' | |
myString = "nim" | |
myInteger = 42 | |
myFloat = 3.14 | |
echo myBool, ":", repr(myBool) | |
# --> true:true | |
echo myCharacter, ":", repr(myCharacter) | |
# --> n:'n' |
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
var | |
x: int32 = 1.int32 # same as calling int32(1) | |
y: int8 = int8('a') # 'a' == 97'i8 | |
z: float = 2.5 # int(2.5) rounds down to 2 | |
sum: int = int(x) + int(y) + int(z) # sum == 100 |
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
iterator countup(a, b: int): int = | |
var res = a | |
while res <= b: | |
yield res | |
inc(res) |
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
#Procedure with implicit return result | |
proc sumTillNegative(x: varargs[int]): int = | |
for i in x: | |
if i < 0: | |
return | |
result = result + i | |
echo sumTillNegative() # echos 0 | |
echo sumTillNegative(3, 4, 5) # echos 12 | |
echo sumTillNegative(3, 4 , -1 , 6) # echos 7 |
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
#Basic if statement | |
let name = readLine(stdin) | |
if name == "": | |
echo "Poor soul, you lost your name?" | |
elif name == "name": | |
echo "Very funny, your name is name." | |
else: | |
echo "Hi, ", name, "!" | |
#Basic case statement |
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
var x, y: int # declares x and y to have the type ``int`` | |
var | |
x, y: int | |
# a comment can occur here too | |
a, b, c: string | |
#Constants | |
const x = "abc" # the constant x contains the string "abc" |
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
r"C:\program files\nim" | |
# A comment. | |
var myVariable: int ## a documentation comment | |
#[ | |
You can have any Nim code text commented | |
out inside this with no indentation restrictions. | |
yes("May I ask a pointless question?") |