module demos; import std; export import foo; // Hello world is simple: proc main_(argv, mut stdio) = stdio.out.print("Hello, world!"); proc abc(&mut `in`, &mut out) { let mut a : [11]f64; for &mut v in a { `in`.parse(&v) ?? die("Invalid input (expected number)\n") } else None; for i in rev(enumerate(a)) { } ; // should not be necessary if rev(enumerate(a)) { } // no else ; // should not be necessary for i in rev(enumerate(a)) { let y = fun(v); if y > 400 { out.print("{} TOO LARGE\n".format(i)) } else { out.print("{} {}\n".format(i, y)) } } else None } // Some example function declarations: fn func1(); fn func2(arg); fn func3() -> None; fn func4(arg : i32) -> None; fn ns::func5(arg : i32) -> u32; proc func6!0() -> This; proc func7(arg = 0); proc func8(arg : i32 = 0); fn func9(arg1, arg2 : u10, &arg3) -> None; fn func10( -> ); proc main(argv, &mut stdio) -> None; //*/ let verse = "{1} bottles of beer on the wall. {1} bottles of beer.\nTake one down, pass it around, {2} bottles of beer on the wall.\n"; // example of stropping: let `strop` : i32 = 0; let call = f(); let math = 1 + 2 * 4 / (8 - 16); // function declaration export fn format_verse_s(count); #[attr, attr2] namespace ns { // redeclaration fn func5(arg : i31) -> u32; } // Structured syntax #[export(true)] export fn format_verse_s(count) = verse.format(count, count - 1); proc main(argv, mut stdio) { sing_s(stdio.out); sing_c(stdio.out); } fn demo_loop() { loop : demo { } } fn fun(x) = sqrt(abs(x)) + 5 * x.pow(3); proc sing_s(mut out) { for count = 99 -> 1 { out.print(format_verse_s(count)); }; out.print("No more bottles of beer on the wall, no more bottles of beer.\n"); out.print("Go to the store and buy some more, 99 bottles of beer on the wall...\n"); } proc tpk(&mut `in`, &mut out) { let mut a : [11]f64; for &mut v in a { `in`.parse(&v) ?? die("Invalid input (expected number)\n") } else None; for i in rev(enumerate(a)) { let y = fun(v); if /*y > 400*/ rev(enumerate(a)) { out.print("{} TOO LARGE\n".format(i)) } else { out.print("{} {}\n".format(i, y)) } } else None } proc tpk_c(&mut `in`, &mut out) (: (let mut a : [11]f64) 0 11 std::seq ( v -> ){ } :) // Substrate syntax fn format_verse_c(count) (: verse count count 1 - format!3 :) proc sing_c(mut out) (: 99 1 std::seq {out swap format_verse_c print} std::map out "No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall...\n" print :) //*/