Skip to content

Instantly share code, notes, and snippets.

@agrif
Created January 12, 2012 00:46
Show Gist options
  • Save agrif/1597754 to your computer and use it in GitHub Desktop.
Save agrif/1597754 to your computer and use it in GitHub Desktop.
// single-line comment
/* multi-line comment */
decl implicit_declaration = 0.5;
int32 explicit_declaration = 5;
int32 extern_declaration;
(int32, int32) tuple = (1, -1);
int32[] pointer_to_ints = [5, 10, 15, 20];
int32[8] pointer_to_ints_explicit = [0, ...];
type (int32 x, int32 y) point;
point a = (1, -1);
/* function, with implicit type */
decl function = (int32 argc, char[][] argv):int32 {
return 0;
}
/* binary operator */
decl oper = (int32 a):(int32 b):int32 {
return a * b;
}
/* method taking void */
decl double = (int32 self):():int32 {
return a * 2;
}
/*
* examples of calling functions, etc
*/
decl main = (int32 argc, char[][] argv) : int32 {
/* type of if: (bool, ():()):bool */
if ((function argc argv) > 0) {
return 1;
}
decl c = 1 oper 2;
/* is it worthwhile to implement return as a function? */
/* OHGODNO */
return c double;
}
/* bottles of beer, with standard library */
decl main = (cint, cchar[][]):cint {
decl numbers = (range 0 100) reverse;
numbers foreach (int32 b):() {
if (b == 0) {
printf "No more bottles of beer on the wall, no more bottles of beer.\n";
printf "Go to the store and buy some more, 99 bottles of beer on the wall.\n";
} elif (b == 1) {
printf "1 bottle of beer on the wall, 1 bottle of beer.\n";
printf "Take one down and pass it around, no more bottles of beer on the wall.\n";
} else {
decl plur = "bottles";
if (b == 2) { plur = "bottle"; };
printf "%d bottles of beer on the wall, %d bottles of beer.\n" b b;
printf "Take one down and pass it around, %d %s of beer on the wall.\n" (b - 1) (b - 1) plur;
};
};
return 0;
};
/* relevant types and declarations */
(uint32, uint32):RangeObject range;
RangeObject:():RangeObject reverse;
RangeObject:((int32):()):() foreach;
(bool, ():()):bool if;
bool:(bool, ():()):bool elif;
bool:(():()):() else;
(char[], ...):cint printf;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment