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
$ cat hello.c | |
int main(void){ | |
if(1); | |
int i = 1; | |
$ gcc hello.c -std=c89 -pedantic | |
hello.c: In function ‘main’: | |
hello.c:3:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement] | |
int i = 1; | |
^~~ |
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
linear_hash | |
Profiling Set - repeating keys | |
10000000 set(s) took '1790' ms total or '0.179000' ns each | |
10000000 get(s) took '1711' ms total or '0.171100' ns each | |
10000000 exists(s) took '1621' ms total or '0.162100' ns each | |
Profiling Set - unique keys | |
35591 set(s) took '14' ms total or '0.393358' ns each | |
35591 get(s) took '7' ms total or '0.196679' ns each |
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
A syntax I am playing with can be seen here; every reference is immutable by | |
default but mutability can be opted into using an ampersand (`&`): | |
# function that will add `1` to every mutable Signed Integer in a mutable List | |
fn add_one(&n::List[&Sint]) | |
for &item in &n | |
&item += 1 | |
end | |
end |
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
// DO NOT USE THIS | |
// heavily derived from Rust's Cell | |
// https://github.com/rust-lang/rust/blob/master/src/libcore/cell.rs | |
struct MyCell<T> { | |
value: T | |
} | |
impl<T:Copy> MyCell<T> { | |
pub fn new(value: T) -> MyCell<T> { |
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
builtin fn minus(Sint, Sint) -> Sint | |
builtin fn divide(Sint, Sint) -> Sint | |
builtin fn print(Sint) | |
fn foo() -> Sint | |
# problem: what should the typing for these literals be ? | |
let a = 16 | |
let b = 24 | |
let c = a / b | |
print(c) |
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
fn main() | |
let &l::List[&Sint8] = [1, 2, 3] | |
&l.append(4) | |
print(l) | |
end | |
# the type of T here *must* be a read only permission type | |
# therefore the typ of `l` in `print(l)` above must be ::List[Sint8] | |
fn print[T](l::List[T]) |
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 Foo | |
b::Bar plus equals divide print | |
c::Baz multiply | |
end |
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
use std::cell::Cell; | |
struct Point { | |
x: i32, | |
y: Cell<i32>, | |
} | |
/* mutate takes an *immutable* reference to a Point */ | |
fn mutate(point: &Point){ | |
point.y.set(1000); |
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
#include <memory.h> | |
#include <assert.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
void *my_memmove(void *dest, const void *src, size_t n); | |
void *my_memmove(void *dest, const void *src, size_t n){ | |
size_t i = 0; | |
size_t j = 0; |
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
package main | |
import "fmt" | |
func adder(first int) func(int) int { | |
func inner(second int) int { | |
return first + second | |
} | |
return inner | |
} |