changes for new grammar, fixes

This commit is contained in:
ProgramSnail 2023-06-03 19:01:03 +03:00
parent 91f9affadc
commit 3106a64949
35 changed files with 605 additions and 550 deletions

View file

@ -1,14 +1,14 @@
decl test_arrays : -> Unit
def test_arrays = {
decl test-arrays : -> \unit
def test-arrays = {
var arr1 = ,1 ,2 ,3
const arr2 = Int._array: 32
var arr3 = String._array: 11
const arr4 = 'a'--'z'
const arr2 = \int..array: 32
var arr3 = \string..array: 11
const arr4 = ''a--''z
const n = 100
var arr5 <- Int._new_array: 10
var arr5 <- \int..new-array: 10
var arr6 <- String._new_array: 10
var arr6_reference = ^arr6
var arr6 <- \string..new-array: 10
var arr6-reference = ^arr6
const elem1 = arr1`0
var elem2 = arr1`2

View file

@ -1,59 +1,59 @@
struct Fruit =
| Apple
| Orange
| Banana
struct \fruit =
| $apple
| $orange
| $banana
struct Optional 'A =
| Some & 'A
| None
struct \optional 'a =
| $some & 'a
| $none
struct (Result : #Move) 'A 'B =
| & 'A
| Error & 'B
struct \result[#move] 'a 'b =
| & 'a
| $error & 'b
struct (Complex : #Value) =
& Float
& Float
struct \complex[#value] =
& \float
& \float
struct Task =
& name : String
& duration : Float!
struct \task =
& name : \string
& duration : \float?
class Employee =
& name : String
class \employee =
& name : \string
& role :
( | Director
& importance : Float
& share : Float
| Manager
( | $director
& importance : \float
& share : \float
| $manager
& productivity :
( Productivity
| .Low
| .Average
| .High
& duration : Float
& sleep_on_work :
(SleepOnWork
| ..Yes
| ..No
( \productivity
| $.low
| $.average
| $.high
& duration : \float
& sleep-on-work :
( \sleep-on-work
| $..yes
| $..no
))
& salary : Int
| Programmer
& skills : Float
& current_task : (Optional Task)
& salary : Int)
& salary : \int
| $programmer
& skills : \float
& current-task : \optional[task]
& salary : \int)
class Bag =
class \bag =
&
( | Apple
| Orange
| Banana)
& bag_type :
( | Small
| Medium
& weight_kg : Int
& weight_g : Int
& weight_g : Int
| Big)
& other_things : (Array Something)
( | $apple
| $orange
| $banana)
& bag-type :
( | $small
| $medium
& weight-kg : \int
& weight-g : \int
& weight-mg : \int
| $big)
& other-things : \array[something]

View file

@ -1,44 +1,18 @@
namespace Employee {
decl gen_employee : Unit -> Employee
def gen_employee = {
var x = $@Complex & 11.3 & 15.87 // construct on heap
namespace \employee {
decl gen-employee : \unit -> \employee
def gen-employee = {
var x = $@complex & 11.3 & 15.87 // construct on heap
return
$Employee // construct on stack
$employee // construct on stack
& name = "John"
& role =
($Manager
($manager
& "John"
& productivity =
($Productivity::High
($productivity.high
& duration = 10.3
& sleep_on_work = ($Productivity::SleepOnWork::No))
& sleep-on-work = ($productivity.sleep-on-work.no))
& salary = 123)
}
}
/*
class Employee =
& name : String
& role :
( | Director
& importance : Float
& share : Float
| Manager
& productivity :
( Productivity
| .Low
| .Average
| .High
& duration : Float
& sleep_on_work :
(SleepOnWork
| ..Yes
| ..No
))
& salary : Int
| Programmer
& skills : Float
& current_task : Optional Task
& salary : Int)
*/

View file

@ -1,28 +1,28 @@
decl flow_control_test : -> Unit
def flow_control_test = {
if (a < b ||. a == b) && (b < c) then IO.print: x
decl flow-control-test : -> \unit
def flow-control-test = {
if (a < b ||. a == b) && (b < c) then \io..print: x
elif x < 0 then {
; x += 1
; IO.print: y
; \io..print: y
} else {
return {}
}
while (a > 0) && not: (array.is_empty:) do {
while (a > 0) && not: (array..is-empty:) do {
; a -= 1
; array.pop:
; array..pop:
}
while x < 10 do x +=. x + 3
for i in 0--y do {
; IO.print: i
; \io..print: i
}
for & i & j in (& 0--y & 0--k) do { // ??
; IO.print: 1
; IO.print: 2
; IO.print: 128
; \io..print: 1
; \io..print: 2
; \io..print: 128
}
loop {

View file

@ -1,62 +1,62 @@
decl sum ('A : #Add) : 'A -> 'A -> 'A
decl sum 'a[#add] : 'a -> 'a -> 'a
def sum : a b = a + b
decl fib : Int -> Int
decl fib : \int -> \int
def fib : n =
match n with
| 0 | 1 -> 1
| n ? n > 1 -> fib: (n - 1) + fib: n
| n ?? n > 1 -> fib: (n - 1) + fib: n
| _ -> error: "n must be positive"
decl fact : Int -> Int
decl fact : \int -> \int
def fact : n =
match n with
| 0 -> 1
| n ? n > 0 -> n * fact: (n - 1)
| n ?? n > 0 -> n * fact: (n - 1)
| _ -> error: "n must be positive"
decl find_prefix_hashes ('H : (#AccHash Char)) : String -> (Array 'H)
def find_prefix_hashes : str = {
var hashes = (Array 'H).new: (str.size: + 1)
decl find-prefix-hashes 'h[#acc-hash[char]] : \string -> \array['h]
def find-prefix-hashes : str = {
var hashes = \array['h]..new: (str..size: + 1)
; hashes`0 = 'H.of: str`0
for i in 1--hashes.size: do {
; hashes`0 = 'h..of: str`0
for i in 1--hashes..size: do {
; hashes`i = hashes`(i - 1)
; hashes`i.append: str`i
; hashes`i..append: str`i
}
return hashes
}
alias Hash = (AccHash Char)
alias \hash = \acc-hash[char]
decl find_substring : String -> String -> (Array Index)
def find_substring : str substr = {
var result = (Array Index).empty:
decl find-substring : \string -> \string -> \array[index]
def find-substring : str substr = {
var result = \array[index]..empty:
const str_hashes = find_prefix_hashes Hash: str
const substr_hash = Hash.of: substr
const str-hashes = find-prefix-hashes:[hash] str
const substr-hash = \hash..of: substr
for i in 0--(str_hashes.size: - substr.size:) do {
const part_hash = Hash.diff: str_hashes`(i + substr.size:) str_hashes`i
for i in 0--(str-hashes..size: - substr..size:) do {
const part-hash = hash..diff: str-hashes`(i + substr..size:) str-hashes`i
if part_hash == substr_hash then {
; result.push: i
if part-hash == substr-hash then {
; result..push: i
}
}
return result
}
decl is_empty : -> Bool
def is_empty = 0
decl is-empty : -> \bool
def is-empty = 0
decl do_something : -> Unit
def do_something =
IO.print: "Hello World!"
decl do-something : -> \unit
def do-something =
\io..print: "Hello World!"
decl mul : Int -> Int -> Int
decl mul : \int -> \int -> \int
def mul : x y = x * y
decl mul_10 : Int -> Int
def mul_10 = mul: 10
decl mul-10 : \int -> \int
def mul-10 = mul: 10

View file

@ -1,15 +1,15 @@
import "module"
import "module" : func
import "module" :
Type1
\type1
func1
func2
func3
func4
use ModuleNamespace = import "module"
use module-namespace = import "module"
use PartOfModuleNamespace =
use part-of-module-namespace =
import "module" :
func1
func2

View file

@ -1,11 +1,11 @@
decl test_lambdas : -> Unit
def test_lambdas = {
const lambda1 = \x -> x * x
const lambda2 = \x -> x.hash:
const lambda3 = \x y -> x + y
decl test-lambdas : -> \unit
def test-lambdas = {
const lambda1 = \\x -> x * x
const lambda2 = \\x -> x..hash:
const lambda3 = \\x y -> x + y
const lambda4 = \x -> {
; IO.print: x
const lambda4 = \\x -> {
; \io..print: x
const y = x + x
return y
}

View file

@ -1,18 +1,18 @@
decl fruit_cost : Fruit -> Int
def fruit_cost : fruit = {
var fruit_copy = fruit
return (match <- fruit_copy with // consuming match
| $Banana -> 11
| $Apple | $Orange -> 7)
decl fruit-cost : \fruit -> \int
def fruit-cost : fruit = {
var fruit-copy = fruit
return (match <- fruit-copy with // consuming match
| $banana -> 11
| $apple | $orange -> 7)
}
decl amount_to_string : Int -> Bool -> String
def amount_to_string : x is_zero_separated = {
decl amount-to-string : \int -> \bool -> \string
def amount-to-string : x is-zero-separated = {
const ans = match x with
| 0 ? is_zero_separated -> "Zero"
| 0 ?? is-zero-separated -> "Zero"
| 0 | 1 | 2 | 3 | 4 -> "Few"
| x ? (5--9).contains: x -> "Several"
| x ? (10--19).contains: x -> "Pack"
| x ?? (5--9)..contains: x -> "Several"
| x ?? (10--19)..contains: x -> "Pack"
| _ -> "Lots"
return ans
}

View file

@ -1,8 +1,8 @@
struct StructWithRef =
& @Int_0
struct \struct-with-ref =
& @\int`0
decl test_memory : -> Unit
def test_memory = {
const unique_ref1 <- Int._new: 5
var unique_ref2 <- Array.of: 1 2 3
decl test-memory : -> \unit
def test-memory = {
const unique-ref1 <- \int..new: 5
var unique-ref2 <- \array..of: 1 2 3
}

View file

@ -1,19 +1,19 @@
namespace Namespace {
decl something : -> Unit
namespace some-namespace {
decl something : -> \unit
}
namespace Array {
decl something : -> Unit
namespace \array {
decl something : -> \unit
}
namespace Array {
decl something : -> Unit
namespace \array {
decl something : -> \unit
}
namespace var Array {
decl something : -> Unit
namespace var \array {
decl something : -> \unit
}
namespace const Array {
decl something : -> Unit
namespace const \array {
decl something : -> \unit
}

View file

@ -1,10 +1,10 @@
test All::Dev::Syntax::testing {
test all.dev.syntax.testing {
const a = 31
; do_something: a
; do-something: a
}
exec App::exe {
exec app.exe {
const b = true
const c = false
; do_something_different: b b c
; do-something-different: b b c
}

View file

@ -1,19 +1,19 @@
basic (Float : #Ord #Div #Str)
basic (Int : #Ord #IDiv #Str)
basic (String : #Ord #Str #CharContainer #Copy)
basic (Char : #Ord #Str #Copy)
basic (Bool : #Ord #Str #Copy)
basic (Unit : #Str #Copy)
basic \float[#ord #div #str]
basic \int[#ord #idiv #str]
basic \string[#ord #str #char-container #copy]
basic \char[#ord #str #copy]
basic \bool[#ord #str #copy]
basic \unit[#str #copy]
//
decl not : Bool -> Bool
decl not : \bool -> \bool
def not : x =
(match x with
| true -> false
| false -> true)
decl ( && ) : Bool -> Bool -> Bool
decl ( && ) : \bool -> \bool -> \bool
def ( && ) : x y =
match x with
| true -> (
@ -23,7 +23,7 @@ def ( && ) : x y =
)
| false -> false
decl ( || ) : Bool -> Bool -> Bool
decl ( || ) : \bool -> \bool -> \bool
def ( || ) : x y =
match x with
| true -> true
@ -35,28 +35,28 @@ def ( || ) : x y =
//
typeclass CharContainer =
& var size : -> Int
& var at : Int -> Char
typeclass \char-container =
& var size : -> \int
& var at : \int -> \char
//
typeclass Move = // TODO
& var ( <- ) : Move -> Unit
typeclass \move = // TODO
& var ( <- ) : \move -> \unit
typeclass Copy =
& var ( = ) : Copy -> Unit
typeclass \copy =
& var ( = ) : \copy -> \unit
//
typeclass (Sum : #Copy) =
& var ( += ) : Sum -> Unit
& var ( -= ) : Sum -> Unit
& var ( + ) : Sum -> Sum
& var ( - ) : Sum -> Sum
& zero : -> Sum
typeclass \sum[#copy] =
& var ( += ) : \sum -> \unit
& var ( -= ) : \sum -> \unit
& var ( + ) : \sum -> \sum
& var ( - ) : \sum -> \sum
& zero : -> \sum
namespace var Sum {
namespace var \sum {
def ( + ) : x = {
var ans = self
; ans += x
@ -70,11 +70,11 @@ namespace var Sum {
}
}
typeclass (Mult : #Sum) =
& var ( *= ) : Mult -> Unit
& var ( * ) : Mult -> Mult
typeclass \mult[#sum] =
& var ( *= ) : \mult -> \unit
& var ( * ) : \mult -> \mult
namespace var Mult {
namespace var \mult {
def ( * ) : x = {
var ans = self
; ans *= x
@ -82,19 +82,19 @@ namespace var Mult {
}
}
typeclass (IDiv : #Mult) =
& var div : IDiv -> IDiv
& var mod : IDiv -> IDiv
typeclass \idiv[#mult] =
& var div : \idiv -> \idiv
& var mod : \idiv -> \idiv
namespace var IDiv {
def mod : x = self -. x * self.div: x
namespace var \idiv {
def mod : x = self -. x * self..div: x
}
typeclass (Div : #Mult) =
& var ( /= ) : Div -> Unit
& var ( / ) : Div -> Div
typeclass \div[#mult] =
& var ( /= ) : \div -> \unit
& var ( / ) : \div -> \div
namespace var Div {
namespace var \div {
def ( / ) : x = {
var ans = self
; ans /= x
@ -104,39 +104,39 @@ namespace var Div {
//
typeclass Eq =
& var ( == ) : Eq -> Bool
& var ( != ) : Eq -> Bool
typeclass \eq =
& var ( == ) : \eq -> \bool
& var ( != ) : \eq -> \bool
namespace var Eq {
namespace var \eq {
def ( != ) : x = not: (self == x)
}
//
struct Order =
| EQ
| LT
| GT
struct \order =
| $eq
| $lt
| $gt
typeclass (Ord : #Eq) =
& var compare : Ord -> Order
& var ( < ) : Ord -> Bool
& var ( >= ) : Ord -> Bool
& var ( > ) : Ord -> Bool
& var ( <= ) : Ord -> Bool
typeclass \ord[#eq] =
& var compare : \ord -> \order
& var ( < ) : \ord -> \bool
& var ( >= ) : \ord -> \bool
& var ( > ) : \ord -> \bool
& var ( <= ) : \ord -> \bool
decl min ('A : #Ord) : 'A -> 'A -> 'A
decl min 'a[#ord] : 'a -> 'a -> 'a
def min : x y = if x < y then x else y
decl max ('A : #Ord) : 'A -> 'A -> 'A
decl max 'a[#ord] : 'a -> 'a -> 'a
def max : x y = if x < y then y else x
namespace var Ord {
namespace var \ord {
def compare : x =
if self == x then $EQ
elif self < x then $LT
else $GT
if self == x then $eq
elif self < x then $lt
else $gt
def ( >= ) : x = not: (self < x)
def ( > ) : x = x < self
@ -145,44 +145,45 @@ namespace var Ord {
//
typeclass Show =
& var show : -> String
typeclass \show =
& var show : -> \string
typeclass Read =
& read : String -> Read
typeclass \read =
& read : \string -> \read
typeclass (Str : #Show #Read)
typeclass \str[#show #read]
// typeclass DebugShow = // TODO
// & debug_show : -> String
// typeclass debug-show = // TODO
// & debugdshow : -> \string
//
typeclass Default =
& default : -> Default
typeclass \default =
& default : -> \default
//
typeclass Bounded =
& min_bound : -> Bounded
& max_bound : -> Bounded
& var is_max_bound : -> Bool
& var is_min_bound : -> Bool
typeclass \bounded =
& min-bound : -> \bounded
& max-bound : -> \bounded
& var is-max-bound : -> \bool
& var is-min-bound : -> \bool
//
typeclass Enum =
& var succ : -> (Optional Enum)
& var pred : -> (Optional Enum)
& to_enum : Int -> Enum
& var from_enum : -> Int
typeclass \enum =
& var succ : -> \optional[enum]
& var pred : -> \optional[enum]
& to-enum : \int -> \enum
& var from-enum : -> \int
//
namespace IO {
decl print : String -> Unit
decl scan : -> String
decl random : -> Int // TODO
namespace io {
decl print : \string -> \unit
decl scan : -> \string
}
decl random : -> \int // TODO
//

View file

@ -1,19 +1,19 @@
basic (Float : #Ord #Div #Str)
basic (Int : #Ord #IDiv #Str)
basic (String : #Ord #Str #CharContainer #Copy)
basic (Char : #Ord #Str #Copy)
basic (Bool : #Ord #Str #Copy)
basic (Unit : #Str #Copy)
basic \float[#ord #div #str]
basic \int[#ord #idiv #str]
basic \string[#ord #str #char-container #copy]
basic \char[#ord #str #copy]
basic \bool[#ord #str #copy]
basic \unit[#str #copy]
//
decl not : Bool -> Bool
decl not : \bool -> \bool
def not : x =
(match x with
| true -> false
| false -> true)
decl ( && ) : Bool -> Bool -> Bool
decl ( && ) : \bool -> \bool -> \bool
def ( && ) : x y =
match x with
| true -> (
@ -23,7 +23,7 @@ def ( && ) : x y =
)
| false -> false
decl ( || ) : Bool -> Bool -> Bool
decl ( || ) : \bool -> \bool -> \bool
def ( || ) : x y =
match x with
| true -> true
@ -35,28 +35,28 @@ def ( || ) : x y =
//
typeclass CharContainer =
& var size : -> Int
& var at : Int -> Char
typeclass \char-container =
& var size : -> \int
& var at : \int -> \char
//
typeclass Move = // TODO
& var ( <- ) : Move -> Unit
typeclass \move = // TODO
& var ( <- ) : \move -> \unit
typeclass Copy =
& var ( = ) : Copy -> Unit
typeclass \copy =
& var ( = ) : \copy -> \unit
//
typeclass (Sum : #Copy) =
& var ( += ) : Sum -> Unit
& var ( -= ) : Sum -> Unit
& var ( + ) : Sum -> Sum
& var ( - ) : Sum -> Sum
& zero : -> Sum
typeclass \sum[#copy] =
& var ( += ) : \sum -> \unit
& var ( -= ) : \sum -> \unit
& var ( + ) : \sum -> \sum
& var ( - ) : \sum -> \sum
& zero : -> \sum
namespace var Sum {
namespace var \sum {
def ( + ) : x = {
var ans = self
; ans += x
@ -70,11 +70,11 @@ namespace var Sum {
}
}
typeclass (Mult : #Sum) =
& var ( *= ) : Mult -> Unit
& var ( * ) : Mult -> Mult
typeclass \mult[#sum] =
& var ( *= ) : \mult -> \unit
& var ( * ) : \mult -> \mult
namespace var Mult {
namespace var \mult {
def ( * ) : x = {
var ans = self
; ans *= x
@ -82,19 +82,19 @@ namespace var Mult {
}
}
typeclass (IDiv : #Mult) =
& var div : IDiv -> IDiv
& var mod : IDiv -> IDiv
typeclass \idiv[#mult] =
& var div : \idiv -> \idiv
& var mod : \idiv -> \idiv
namespace var IDiv {
def mod : x = self -. x * self.div: x
namespace var \idiv {
def mod : x = self -. x * self..div: x
}
typeclass (Div : #Mult) =
& var ( /= ) : Div -> Unit
& var ( / ) : Div -> Div
typeclass \div[#mult] =
& var ( /= ) : \div -> \unit
& var ( / ) : \div -> \div
namespace var Div {
namespace var \div {
def ( / ) : x = {
var ans = self
; ans /= x
@ -104,39 +104,39 @@ namespace var Div {
//
typeclass Eq =
& var ( == ) : Eq -> Bool
& var ( != ) : Eq -> Bool
typeclass \eq =
& var ( == ) : \eq -> \bool
& var ( != ) : \eq -> \bool
namespace var Eq {
namespace var \eq {
def ( != ) : x = not: (self == x)
}
//
struct Order =
| EQ
| LT
| GT
struct \order =
| $eq
| $lt
| $gt
typeclass (Ord : #Eq) =
& var compare : Ord -> Order
& var ( < ) : Ord -> Bool
& var ( >= ) : Ord -> Bool
& var ( > ) : Ord -> Bool
& var ( <= ) : Ord -> Bool
typeclass \ord[#eq] =
& var compare : \ord -> \order
& var ( < ) : \ord -> \bool
& var ( >= ) : \ord -> \bool
& var ( > ) : \ord -> \bool
& var ( <= ) : \ord -> \bool
decl min ('A : #Ord) : 'A -> 'A -> 'A
decl min 'a[#ord] : 'a -> 'a -> 'a
def min : x y = if x < y then x else y
decl max ('A : #Ord) : 'A -> 'A -> 'A
decl max 'a[#ord] : 'a -> 'a -> 'a
def max : x y = if x < y then y else x
namespace var Ord {
namespace var \ord {
def compare : x =
if self == x then $EQ
elif self < x then $LT
else $GT
if self == x then $eq
elif self < x then $lt
else $gt
def ( >= ) : x = not: (self < x)
def ( > ) : x = x < self
@ -145,63 +145,64 @@ namespace var Ord {
//
typeclass Show =
& var show : -> String
typeclass \show =
& var show : -> \string
typeclass Read =
& read : String -> Read
typeclass \read =
& read : \string -> \read
typeclass (Str : #Show #Read)
typeclass \str[#show #read]
// typeclass DebugShow = // TODO
// & debug_show : -> String
// typeclass debug-show = // TODO
// & debugdshow : -> \string
//
typeclass Default =
& default : -> Default
typeclass \default =
& default : -> \default
//
typeclass Bounded =
& min_bound : -> Bounded
& max_bound : -> Bounded
& var is_max_bound : -> Bool
& var is_min_bound : -> Bool
typeclass \bounded =
& min-bound : -> \bounded
& max-bound : -> \bounded
& var is-max-bound : -> \bool
& var is-min-bound : -> \bool
//
typeclass Enum =
& var succ : -> (Optional Enum)
& var pred : -> (Optional Enum)
& to_enum : Int -> Enum
& var from_enum : -> Int
typeclass \enum =
& var succ : -> \optional[enum]
& var pred : -> \optional[enum]
& to-enum : \int -> \enum
& var from-enum : -> \int
//
namespace IO {
decl print : String -> Unit
decl scan : -> String
decl random : -> Int // TODO
namespace io {
decl print : \string -> \unit
decl scan : -> \string
}
//
// // bad
// typeclass Functor 'A =
// & fmap 'B ('F : (#Functor 'B)) : ('A -> 'B) -> Functor -> 'F
// typeclass (Iterator : #Eq) =
// & next : -> Unit
// & prev : -> Unit
//
// typeclass Iterable ('Iter : #Iterable) =
// & begin : -> 'Iter
// & end : -> 'Iter
decl random : -> \int // TODO
//
decl ( -- ) : Int -> Int -> Int_0
// // // bad
// // typeclass \functor 'a =
// // & fmap 'b ('f[#functor['b]]) : ('a -> 'b) -> \functor -> 'f
//
// // typeclass \iterator[#eq] =
// // & next : -> \unit
// // & prev : -> \unit
//
// // typeclass \iterable 'iter[#iterable] =
// // & begin : -> 'iter
// // & end : -> 'iter
//
decl ( -- ) : \int -> \int -> \int`0
def ( -- ) : begin end = {
var current = begin
return (while current < end do {
@ -210,11 +211,11 @@ def ( -- ) : begin end = {
})
}
// decl func : String -> Int -> Int
// decl func : \string -> \int -> \int
// def func : s i = {
// ; print: s
// var x = s
// ; print: (i.show:)
// ; print: (i..show:)
// return 5
// }
//
@ -227,60 +228,60 @@ def ( -- ) : begin end = {
// })
// }
decl scan_int : -> Int
def scan_int = Int.read: (IO.scan:)
decl scan-int : -> \int
def scan-int = \int..read: (\io..scan:)
decl print_int : Int -> Unit
def print_int : x = IO.print: (x.show:)
decl print-int : \int -> \unit
def print-int : x = \io..print: (x..show:)
decl scan_anything ('A : #Read) : -> 'A
def scan_anything = 'A.read: (IO.scan:)
decl scan-anything 'a[#read] : -> 'a
def scan-anything = 'a..read: (\io..scan:)
decl print_anything ('A : #Show) : 'A -> Unit
def print_anything : x = IO.print: (x.show:)
decl print-anything 'a[#show] : 'a -> \unit
def print-anything : x = \io..print: (x..show:)
// decl sorted ('A : #Ord #Copy): 'A_0 -> Int -> 'A_0
// decl sorted 'a[#ord #copy]: 'a`0 -> \int -> 'a`0
// def sorted : a sz = {
// var a_copy = a
// var a-copy = a
// if sz == 2 then {
// if a_copy`0 > a_copy`1 then {
// var x = a_copy`0
// a_copy`0 = a_copy`1
// a_copy`1 = x
// if a-copy`0 > a-copy`1 then {
// var x = a-copy`0
// a-copy`0 = a-copy`1
// a-copy`1 = x
// }
// return a_copy
// return a-copy
// }
//
// var center = sz.div: 2
// var center = sz..div: 2
//
// var a_left = for i in 0--center do a`i
// var a_right = for i in center-sz do a`i
// var a-left = for i in 0--center do a`i
// var a-right = for i in center-sz do a`i
//
// return a_copy
// return a-copy
// }
struct Array 'A = & 'A // 'A_0
// struct \array 'a = & 'a // 'a`0
// namespace Array {
// decl of : 'A_0 -> (Array 'A)
// def of : x = $(Array 'A) & data = x
// namespace \array {
// decl of : 'a`0 -> \array['a]
// def of : x = $array['a] & data = x
// }
struct ThreeTuple = & String & String & String
struct \three-tuple = & \string & \string & \string
decl scan_three_t : -> ThreeTuple
def scan_three_t = $ThreeTuple & IO.scan: & IO.scan: & IO.scan:
decl scan-three-t : -> \three-tuple
def scan-three-t = $three-tuple & \io..scan: & \io..scan: & \io..scan:
decl scan_three : -> (& String & String & String)
def scan_three = & IO.scan: & IO.scan: & IO.scan:
decl scan-three : -> (& \string & \string & \string)
def scan-three = & \io..scan: & \io..scan: & \io..scan:
exec main {
var n = scan_anything Int:
var x = $(Array Int) & 0 // (for _ in 0--n do scan_int:)
; print_anything Int: n
var n = scan-anything:[int]
var x = (for _ in 0--n do scan-int:) // $array[int] & 0
; print-anything:[int] n
var & a & b & c = scan_three_t:
; IO.print: b
var & d & e & f = scan_three:
; IO.print: e
var & a & b & c = scan-three-t:
; \io..print: b
var & d & e & f = scan-three:
; \io..print: e
}

View file

@ -1,8 +1,8 @@
decl test_tuples : -> Unit
def test_tuples = {
var tuple1 = & "a" & 2 & "hello"
decl test-tuples : -> \unit
def test-tuples = {
var tuple1 = & ''a & 2 & "hello"
const & t1 & t2 & t3 = f: x
; tuple1`0 = "b"
; tuple1`0 = ''b
}

View file

@ -1,5 +1,5 @@
decl test_type_casting : -> Unit
def test_type_casting = {
var x = y.as Int:
var k = (f: y x).as Float:
decl test-type-casting : -> \unit
def test-type-casting = {
var x = y..as:[int]
var k = (f: y x)..as:[float]
}

View file

@ -1,29 +1,29 @@
typeclass Default =
& default : -> Copy
typeclass \default =
& default : -> \default
typeclass (Ord : #Eq) =
& var is_less_then : Ord -> Bool
typeclass \ord[#eq] =
& var is-less-then : \ord -> \bool
typeclass (D : #A #B #C) 'A 'B =
& var do_something : -> (& 'A & 'B)
typeclass \d[#a #b #c] 'a 'b =
& var do-something : -> (& 'a & 'b)
typeclass E 'A =
& var do_something : -> 'A
typeclass \e 'a =
& var do-something : -> 'a
decl ( == ) ('A : #Ord) : 'A -> 'A -> Bool
def ( == ) : a b = a.is_equal_to: b
decl ( == ) 'a[#ord] : 'a -> 'a -> \bool
def ( == ) : a b = a..is-equal-to: b
decl ( != ) ('A : #Ord) : 'A -> 'A -> Bool
decl ( != ) 'a[#ord] : 'a -> 'a -> \bool
def ( != ) : a b = not: (a == b)
decl ( < ) ('A : #Ord) : 'A -> 'A -> Bool
def ( < ) : a b = a.is_less_then: b
decl ( < ) 'a[#ord] : 'a -> 'a -> \bool
def ( < ) : a b = a..is-less-then: b
decl ( > ) ('A : #Ord) : 'A -> 'A -> Bool
decl ( > ) 'a[#ord] : 'a -> 'a -> \bool
def ( > ) : a b = not: (a <= b)
decl ( <= ) ('A : #Ord) : 'A -> 'A -> Bool
decl ( <= ) 'a[#ord] : 'a -> 'a -> \bool
def ( <= ) : a b = a < b ||. a == b
decl ( >= ) ('A : #Ord) : 'A -> 'A -> Bool
decl ( >= ) 'a[#ord] : 'a -> 'a -> \bool
def ( >= ) : a b = not: (a < b)

View file

@ -1,8 +1,8 @@
alias T1 = Int
alias \t1 = \int
abstract (T2 : #A #B #C)
abstract \t2[#a #b #c]
// Used to pre-compile module for some types
let T2 = Int
let T2 = Float
let T2 = Complex
let \t2 = \int
let \t2 = \float
let \t2 = \complex

View file

@ -1,6 +1,6 @@
decl test_variants : -> Unit
def test_variants = {
var variant1 = | 'a' | 2 | "hello"
decl test-variants : -> \unit
def test-variants = {
var variant1 = | ''a | 2 | "hello"
var | val | err = f: x
; val -?> "something" // open variant as value in expr
@ -8,7 +8,7 @@ def test_variants = {
; val -!> "nothing" // open variant as None in expr
match variant1 with
| 'a' -> "something"
| ''a -> "something"
| 2 -> "nothing"
| "hello" -> "nothing"
| 11 -> "nothing"