Skip to content

Instantly share code, notes, and snippets.

View simonask's full-sized avatar

Simon Ask Ulsnes simonask

View GitHub Profile
add: [a, b] {
a + b
}
b: add(4, c)
c: add(5, 6)
sideeffect puts(c)
sideeffect puts(muh)
a: 0
result: try {
8 / a
}
if result.error
// DivisionByZeroException, handle it...
else
puts(result.value)
/*
Why we need Continuations in Snow
*/
ArticleController: controller {
.index: {
articles: Article.find(#all)
render(articles)
}
scope_ext: Object.new()
scope_ext.lol: 123
foo: {
puts(lol)
}
foo.inject_scope(scope_ext)
foo() // => "123"
child: fork()
if !child
// this is the child process
while true
message: Process.message_queue.get_next()
// do something with the message
end
else
// this is the mother process
void foo()
{
A a;
goto out;
B b;
out:
return;
}
#include <stdio.h>
struct A { A() { printf("A()\n"); } ~A() { printf("~A()\n"); } };
struct B { B() { printf("B()\n"); } ~B() { printf("~B()\n"); } };
void foo(void* lbl)
{
goto *lbl;
}
func parse_function(input)
{
return_type = parse_type(input)
name = parse_name_token(input)
parameters = parse_parameter_list(input)
body = parse_scope(input)
return new Function(return_type, name, parameters, body)
}
/* simplified; no UNLESS. */
conditional: IF expression EOL body EOL post_conditional { $$ = snow_ast_if_else($2, $4, $6); }
post_conditional: END
| ELSEIF expression EOL body EOL post_conditional { $$ = snow_ast_if_else($2, $4, $6); }
| ELSE body EOL { $$ = $2; }
foo: [a, b] {
a + b
}
foo(2, 3) // => 5
ast: foo.ast.copy()
ast_addition: ast.children(0)
ast_call: ast_addition.children(0)
ast_call_target: ast_call.caller