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
int foo() | |
{ | |
int x = 0; | |
while (x < 10) x += 1; | |
return x; | |
} |
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
-- This is a toy implementation of a purely functional 'imperative language' | |
-- using only pure Haskell functions. | |
-- I am trying to match the rough syntax | |
-- int x = 0; | |
-- while (x<10) x += 1; | |
-- return x; | |
type Env = [(String, Int)] | |
empty :: Env |
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
;; taken from page 38 of 'the swine before perl' http://www.ai.mit.edu/projects/dynlangs/ll1/shriram-talk.pdf | |
(automaton init | |
(init : (c -> more)) | |
(more : (a -> more) | |
(d -> more) | |
(r -> end)) | |
(end : (r -> 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
.POSIX: | |
all: clean default overwrite | |
default: | |
@echo "using default malloc" | |
gcc main.c module.c | |
./a.out | |
@echo "" | |
@rm -rf *.out *.o |
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
.POSIX: | |
all: clean default overwrite | |
default: | |
@echo "using bar_default implementation" | |
gcc main.c module.c | |
./a.out | |
@echo "" | |
@rm -rf *.out *.o |
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 <stdio.h> | |
#include <unistd.h> | |
int main(void) { | |
/* FD for stdout is 1 */ | |
if (isatty(1)) { | |
fputs("my stdout is a terminal", stderr); | |
} else { | |
fputs("my stdout is NOT a terminal", stderr); | |
} |
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
int main(void) { | |
M : { // a region called M | |
int M results[] = generate_results<M>(); | |
/* use results in some way... */ | |
} /* results are destroyed here */ | |
} | |
void generate_results<R>(void) { | |
int R *my_results = rmalloc(R, size-goes-here); | |
/* do some work on my_results */ |
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
int<?> max(int A *x, int B *y) { | |
C : { | |
int *m = x; | |
if (y > x) { | |
m = y; | |
} | |
return m; | |
} | |
} |
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
-- derived from https://gist.github.com/DomNomNom/060156de8472d9276e34262bfaef031f | |
data Direction = Up | Down | |
czz :: [Int] -> Int | |
czz (x:(y:rest)) | x < y = czz' (y:rest) 0 Up | |
czz (x:(y:rest)) | x > y = czz' (y:rest) 0 Down | |
czz (x:(y:rest)) | x == y = czz (y:rest) | |
czz _ = 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
(A (B (D) (E)) (C (F) (G))) | |
A | |
B C | |
D E F G | |
NewerOlder