Something went wrong. Try again.
The Mesa programming language
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384import Core.Errors.Errorimport Core.Behaviors.Access
def unused raise Error.KeyError("boom")end
def unused_rescue do 1 rescue e case Error.KeyError then $print(e.message) else $print("other") endend
#> parsed$print("parsed")
x := do 1 + 2end#> 3$print(x)
do raise Error.KeyError("boom")rescue e case Error.KeyError then #> caught: boom $print("caught: " + e.message)end
do unknown()rescue e case Error.NameError then #> name 'unknown' is not defined $print(e.message)end
do raise Error.KeyError("boom")rescue e case Error.IndexError then $print("wrong arm")else #> other $print("other")end
do raise 5rescue e case Num then #> 5 $print(e)end
do raise "boom"rescue e case Str then #> boom $print(e)end
do raise [1, 2]rescue e case List then #> [1, 2] $print(e)end
type Task(priority) def status "queued" endend
type Collection(items: []) impl Access
def access(key) items[key] endend
do raise Task(1)rescue e case Task then #> 1 $print(e.priority)end
do each x in 1 do endrescue e case Error.ProtocolError then #> Error.ProtocolError(cause: ProtocolError.NotIterable(message: "type Num is not iterable")) $print(e)end
do 5[0]rescue e case Error.ProtocolError then #> Error.ProtocolError(cause: ProtocolError.NotAccessible(message: "type Num is not accessible")) $print(e)end
do {}.access([1])rescue e case Error.ProtocolError then #> Error.ProtocolError(cause: ProtocolError.NotHashable(message: "type List is not hashable")) $print(e)end
do Collection()[0] := "Item"rescue e case Error.ProtocolError then #> Error.ProtocolError(cause: ProtocolError.NotImplemented(message: "type Collection does not implement 'store'")) $print(e)end
do {} << "x"rescue e case Error.ProtocolError then #> Error.ProtocolError(cause: ProtocolError.NotAppendable(message: "type Dict is not appendable")) $print(e)end
do Task(1) < Task(2)rescue e case Error.ProtocolError then #> Error.ProtocolError(cause: ProtocolError.NotOrderable(message: "type Task is not orderable")) $print(e)end
do n := 1 n()rescue e case Error.TypeError then #> Error.TypeError(cause: TypeError.NotCallable(message: "type Num is not callable")) $print(e)end
do Char()rescue e case Error.TypeError then #> Error.TypeError(cause: TypeError.NotConstructible(message: "type Char cannot be constructed")) $print(e)end
do &1rescue e case Error.TypeError then #> Error.TypeError(cause: TypeError.NotInvocable(message: "type Num is not invocable")) $print(e)end
do n := 5 m := 7 when n case m then "seven" endrescue e case Error.TypeError then #> Error.TypeError(cause: TypeError.CaseNonType(message: "type Num cannot be matched against")) $print(e)end
do $print([1, 2, 3]["a"])rescue e case Error.TypeError then #> Error.TypeError(cause: TypeError.IndexNonNum(message: "index \"a\" is not a number")) $print(e)end
do $print(5.1 + "str")rescue e case Error.TypeError then #> Error.TypeError(cause: TypeError.ArithNonNum(message: "type Str cannot be used in arithmetic")) $print(e)end
do $print("str" + 5.1)rescue e case Error.TypeError then #> Error.TypeError(cause: TypeError.ConcatNonStr(message: "type Num cannot be concatenated")) $print(e)end
def need(a) aend
def pair(a, b) bend
def named(a, b: 1) aend
def twice(a, b: 1) aend
do need()rescue e case Error.ArgumentError then #> Error.ArgumentError(cause: ArgumentError.Missing(message: "missing arg 'a'")) $print(e)end
do pair(1, 2, 3)rescue e case Error.ArgumentError then #> Error.ArgumentError(cause: ArgumentError.TooMany(message: "too many args; have 3, want at most 2")) $print(e)end
do named(1, x: 2)rescue e case Error.ArgumentError then #> Error.ArgumentError(cause: ArgumentError.Unknown(message: "no param named 'x'")) $print(e)end
do twice(1, a: 2)rescue e case Error.ArgumentError then #> Error.ArgumentError(cause: ArgumentError.Duplicate(message: "arg 'a' given twice")) $print(e)end
do $print([1, 2, 3][3])rescue e case Error.IndexError then #> Error.IndexError(cause: IndexError.OutOfRange(message: "index 3 is out of bounds")) $print(e)end
do $print([1, 2, 3][1.7])rescue e case Error.IndexError then #> Error.IndexError(cause: IndexError.NonIntegral(message: "index 1.7 is not a whole number")) $print(e)end
do Task(1).unknownrescue e case Error.MemberError then #> Error.MemberError(cause: MemberError.Missing(message: "type Task has no such member 'unknown'")) $print(e)end
do Task(1).status := "done"rescue e case Error.MemberError then #> Error.MemberError(cause: MemberError.ReadOnly(message: "member 'status' on type Task is read-only")) $print(e)end
do $print(nope)rescue e case Error.NameError then #> Error.NameError(message: "name 'nope' is not defined") $print(e)end
do $print({"a": 1}["b"])rescue e case Error.KeyError then #> Error.KeyError(message: "key \"b\" not found") $print(e)end
do raise Error.KeyError("boom")rescue case Error.KeyError then #> caught without binding $print("caught without binding")end
do raise Error.KeyError("boom")rescue case Error.IndexError then $print("wrong arm")else #> other, no binding $print("other, no binding")end
do unknown()rescue case Error.NameError then #> caught native error without binding $print("caught native error without binding")end
do do raise Error.KeyError("boom") rescue case Error.KeyError then $print(e) endrescue e case Error.NameError then #> name 'e' is not defined $print(e.message)end
#---
#! runtime error: Error.KeyError(message: "boom")
import Core.Errors.Error
raise Error.KeyError("boom")
#---
#! runtime error: Error.KeyError(message: "boom")
import Core.Errors.Error
do raise Error.KeyError("boom")rescue e case Error.IndexError then $print("wrong arm")end
#---
#! runtime error: 5
raise 5
#---
#! runtime error: "boom"
raise "boom"
#---
#! runtime error: type Error
import Core.Errors.Error
raise Error
#---
#! runtime error: type Error.KeyError(message)
import Core.Errors.Error
raise Error.KeyError
#---
#! runtime error: Point(x: 1, y: 2)
type Point(x, y) end
raise Point(1, 2)
#---
import Core.Errors.Errorimport Core.Errors.ProtocolError
type Task(name) def inspect "task" endend
do $print({}[Task("a")])rescue e case Error.ProtocolError then #> Error.ProtocolError(cause: ProtocolError.NotHashable(message: "type Task is not hashable")) $print(e) when e.cause case ProtocolError.NotHashable then #> caught NotHashable $print("caught NotHashable") endend