Skip to content

Instantly share code, notes, and snippets.

View yakkomajuri's full-sized avatar

Yakko Majuri yakkomajuri

View GitHub Profile
# 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:
# All of these mean the same thing
foo(bar)
bar.foo()
bar.foo
foo bar
foo:
bar
// 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
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) {
var (
x int
y int
)
// same as this
var x int
var y int
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]
for (int i = 0; i < 5; ++i) printf("%d\n", i);
let rec fib = function | 0 -> 0 | 1 -> 1 | n -> fib (n - 1) + fib (n - 2)
(x, y, z) = (4, 5, 6)
(x:xs) = [1, 2, 3, 4]
(x, y) = (4, 5)
nats = [1..]
evens = [i | i <- nats, even i]
squares = [i^2 | i <- evens]
pairs = [(x,y) | x <- [0..99], y <- [0..99]]