This file contains 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
# If you declare a function like this: | |
proc helloWorld(s: string) = | |
echo s | |
# You can call it using any of these: | |
helloWorld() | |
hello_world() | |
helloworld() | |
# But not this: |
This file contains 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
# All of these mean the same thing | |
foo(bar) | |
bar.foo() | |
bar.foo | |
foo bar | |
foo: | |
bar |
This file contains 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
// If you define a Tree class like this: | |
sealed trait Tree[A] | |
case class Branch[A](l: Tree[A], r: Tree[A], v: A) extends Tree[A] | |
case class Leaf[A](v: A) extends Tree[A] | |
// Then summing up the tree can be done like this: | |
def sum(tree: Tree[Int]): Int = tree match { | |
case Branch(l, r, v) => sum(l) + sum(r) + v | |
case Leaf(v) => v |
This file contains 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 Y struct { | |
someVar int | |
} | |
func (y *Y) doStuffWithY(x int) { | |
y.someVar = ... | |
} | |
// the above is exactly the same as | |
func doStuffWithY(y *Y, x int) { |
This file contains 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 int | |
y int | |
) | |
// same as this | |
var x int | |
var y int |
This file contains 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 arr = [1, 2, 3] | |
// This: | |
let [a, b, c] = arr | |
// Is the same as this: | |
let a = arr[0], b = arr[1], c = arr[2] |
This file contains 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
for (int i = 0; i < 5; ++i) printf("%d\n", i); |
This file contains 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
let rec fib = function | 0 -> 0 | 1 -> 1 | n -> fib (n - 1) + fib (n - 2) |
This file contains 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
(x, y, z) = (4, 5, 6) | |
(x:xs) = [1, 2, 3, 4] | |
(x, y) = (4, 5) |
This file contains 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
nats = [1..] | |
evens = [i | i <- nats, even i] | |
squares = [i^2 | i <- evens] | |
pairs = [(x,y) | x <- [0..99], y <- [0..99]] |