Skip to content

Instantly share code, notes, and snippets.

package main
func main() {
// Two new vars, with :=.
x, y := returns_one_and_two()
print("x = ", x, "\n") // 1
print("y = ", y, "\n") // 2
// One of the vars is new, use := for both.
y, z := returns_one_and_two()
@erikcorry
erikcorry / aliasing-slices.go
Created March 24, 2021 09:43
Golang slices sometimes alias their underlying array, and sometimes don't.
// Prints false, false, false, true, false, true, true, false, true.
package main
func main() {
for i := 0; i < 10; i++ {
println(doesItAlias(i))
}
}
@vidarh
vidarh / closures-basic.c
Created December 18, 2009 12:10
A number of ways to implement closures in C, in preparation of an upcoming blog post
#include <stdio.h>
#include <stdlib.h>
struct closure {
void (* call)(struct closure *);
int x;
};