//L1 is a term from linguistics that means "native language" //Types type I64 = /^[-]?[0-9]+$/; type U64 = /^[0-9]+$/; type F64 = /^[0-9]+(\.[0-9]+)?$/; type Whole: Integer = /^[0-9]+$/; type Integer: I64 = /^[-]?[0-9]+$/; type U8 = /^[0-9]+$/; type Boolean: U8 = False | True; type String = /^["][^"]*["]$/; type Even: Integer where. self % 2 | 0; type Odd: Integer where. self % 2 | 1; type Prime: Integer where. self > 1 and a:Integer. 2 > a || a > self - 1 || self % a != 0; //Implicit Operators extern $"+"(x: U64, y: U64): U64 = $"+:(U64,U64)->U64"; extern $"-"(x: U64, y: U64): U64 = $"-:(U64,U64)->U64"; extern $"*"(x: U64, y: U64): U64 = $"*:(U64,U64)->U64"; extern $"/"(x: U64, y: U64): U64 = $"/:(U64,U64)->U64"; extern $"%"(x: U64, y: U64): U64 = $"%:(U64,U64)->U64"; extern $"=="(x: U64, y: U64): U8 = $"==:(U64,U64)->U8"; extern $"!="(x: U64, y: U64): U8 = $"!=:(U64,U64)->U8"; extern $"<"(x: U64, y: U64): U8 = $"<:(U64,U64)->U8"; extern $"<="(x: U64, y: U64): U8 = $"<=:(U64,U64)->U8"; extern $">"(x: U64, y: U64): U8 = $">:(U64,U64)->U8"; extern $">="(x: U64, y: U64): U8 = $">=:(U64,U64)->U8"; let pos(x: U64): U64 = x; let neg(x: U64): I64 = (0:I64) - (x as I64); extern $"+"(x: I64, y: I64): I64 = $"+:(I64,I64)->I64"; extern $"-"(x: I64, y: I64): I64 = $"-:(I64,I64)->I64"; extern $"*"(x: I64, y: I64): I64 = $"*:(I64,I64)->I64"; extern $"/"(x: I64, y: I64): I64 = $"/:(I64,I64)->I64"; extern $"%"(x: I64, y: I64): I64 = $"%:(I64,I64)->I64"; extern $"=="(x: I64, y: I64): U8 = $"==:(I64,I64)->U8"; extern $"!="(x: I64, y: I64): U8 = $"!=:(I64,I64)->U8"; extern $"<"(x: I64, y: I64): U8 = $"<:(I64,I64)->U8"; extern $"<="(x: I64, y: I64): U8 = $"<=:(I64,I64)->U8"; extern $">"(x: I64, y: I64): U8 = $">:(I64,I64)->U8"; extern $">="(x: I64, y: I64): U8 = $">=:(I64,I64)->U8"; let pos(x: I64): I64 = x; let neg(x: I64): I64 = (0:I64) - x; extern $"+"(x: F64, y: F64): F64 = $"+:(F64,F64)->F64"; extern $"-"(x: F64, y: F64): F64 = $"-:(F64,F64)->F64"; extern $"*"(x: F64, y: F64): F64 = $"*:(F64,F64)->F64"; extern $"/"(x: F64, y: F64): F64 = $"/:(F64,F64)->F64"; extern $"%"(x: F64, y: F64): F64 = $"%:(F64,F64)->F64"; extern $"=="(x: F64, y: F64): U8 = $"==:(F64,F64)->U8"; extern $"!="(x: F64, y: F64): U8 = $"!=:(F64,F64)->U8"; extern $"<"(x: F64, y: F64): U8 = $"<:(F64,F64)->U8"; extern $"<="(x: F64, y: F64): U8 = $"<=:(F64,F64)->U8"; extern $">"(x: F64, y: F64): U8 = $">:(F64,F64)->U8"; extern $">="(x: F64, y: F64): U8 = $">=:(F64,F64)->U8"; let pos(x: F64): F64 = x; let neg(x: F64): F64 = (0:F64) - x; extern not(x:U8): U8 = $"not:(U8)->U8"; extern $"&&"(a:U8, b:U8): U8 = $"&&:(U8,U8)->U8"; extern $"||"(a:U8, b:U8): U8 = $"||:(U8,U8)->U8"; extern $"as"(x:U64): String = $"as:(U64)->String"; extern $"as"(x:I64): String = $"as:(I64)->String"; extern $"[]"(base: T[], index: I64): T = $"[]:(Tuple,U64)->Value"; extern .length(base: T[]): I64 = $".length:(Tuple)->U64"; extern .flatten(base: T[][]): T[] = $".flatten:(Tuple)->Tuple"; extern range(to: I64): I64[] = $"range:(I64)->I64[]"; extern range(from: I64, to: I64): I64[] = $"range:(I64,I64)->I64[]"; extern range(from: I64, to: I64, step: I64): I64[] = $"range:(I64,I64,I64)->I64[]"; let $"^"(x: I64, n: I64): I64 = if n==0 then 1 else if n%2==0 then (x*x)^(n/2) else x*((x*x)^((n - 1)/2)); extern .flatmap(iterable: X[], f: (X)->(T[])): T[] = $".flatmap:XYZ"; //no body for now, must rewrite term to use extern .join(xs: String[]): String = $".join:(String[])->String"; extern .join2(xs: String[],sep: String): String = $".join:(String[],String)->String"; let .join(xs: T[],sep: String): String = (for x:T in xs yield (x as String)).join2(sep); let $"+"(x: String, y: String): String = f"{x}{y}";