Something went wrong. Try again.
The Mesa programming language
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310import Core.Behaviors.Hash
type Task(priority) impl Hashend
type Group(task) impl Hash
status := "queued"end
dict := {}dict[Task(1)] := "first"#> first$print(dict[Task(1)])
dict[Group(Task(2))] := "group"#> group$print(dict[Group(Task(2))])
type Node(next) impl Hashend
self_loop := Node(nil)self_loop.next := self_loop
two_cycle := Node(nil)two_cycle_next := Node(two_cycle)two_cycle.next := two_cycle_next
#> true$print(self_loop == two_cycle)dict[self_loop] := "cycle"#> cycle$print(dict[two_cycle])
#---
import Core.Behaviors.Hash
type Task(priority) impl Hashend
#> true$print(nil.hash != (0).hash)#> true$print((0).hash != false.hash)#> true$print(false.hash != true.hash)#> true$print(Task.hash != Task(1).hash)#> true$print(Task(1).hash != Task(2).hash)#> true$print((0).hash == (0 * (0 - 1)).hash)#> 1zero := {}zero[0] := "pos"zero[0 * (0 - 1)] := "neg"$print(zero.size)
#---
#! runtime error: type Task is not hashable
type Task(priority)end
{}[Task(1)]
#---
#! runtime error: type List is not hashable
import Core.Behaviors.Hash
type Group(tasks) impl Hashend
{Group([Task(1)]): "group"}
type Task(priority)end
#---
import Core.Behaviors.Hash
type Task(priority) impl Hash
def hash $print("custom hash") (1).hash endend
dict := {}#> custom hashdict[Task(1)] := "task"#> custom hash#> task$print(dict[Task(1)])
#---
import Core.Behaviors.Hash
type Task(priority) impl Hash
def equal(other) true end
def hash (0).hash endend
dict := {Task(1): "task"}#> task$print(dict[Task(2)])
#---
import Core.Behaviors.Hash
type Meddler(id) impl Hash
dict := nil
def hash (0).hash end
def equal(other) when self.dict != nil then meddled := self.dict self.dict := nil meddled[Meddler(other.id)] := "meddled" end self.id == other.id endend
dict := {}first := Meddler(1)dict[first] := "first"first.dict := dictdict[Meddler(2)] := "second"
#> 2$print(dict.size)#> second$print(dict[Meddler(2)])
#---
#! runtime error: type Task is not hashable
import Core.Behaviors.Hash
type Task(priority) impl Hash
def hash "not a number" endend
{Task(1): "task"}
#---
import Core.Behaviors.Hash
type Account(id, name) impl Hash
def hash self.id.hash + self.name.hash endend
#> true$print(Account(1, "a").hash == Account(1, "a").hash)#> true$print(Account(1, "a").hash != Account(2, "a").hash)#> true$print(Account(1, "a").hash != Account(1, "b").hash)#> true$print(Account(1, 2).hash != Account(2, 1).hash)
dict := {}dict[Account(1, "a")] := "first"dict[Account(2, "a")] := "second"dict[Account(1, "b")] := "third"#> 3$print(dict.size)#> second$print(dict[Account(2, "a")])
#---
#! runtime error: type Num cannot be mixed into a digest
import Core.Behaviors.Hash
(1).hash + 5
#---
import Core.Behaviors.Hash
type Task case Ready(priority) impl Hash
def equal(other) true end end
def hash (0).hash endend
dict := {Task.Ready(1): "ready"}#> ready$print(dict[Task.Ready(2)])
#---
#! semantic error: type 'Task' must declare 'hash' when overriding 'equal' and implementing 'Hash'
import Core.Behaviors.Hash
type Task(priority) impl Hash
def equal(other) true endend
#---
import Core.Behaviorsimport Core.Behaviors.Hashimport Test.Leftimport Test.Left.Ready
def run "run"end
type Task def run "task" endend
proto Waiting def wait endend
proc := &runmethod := &Task().run
dict := {}dict[proc] := "proc"dict[method] := "method"dict[Task] := "type"dict[Left] := "module"dict[Waiting] := "proto"dict[Ready] := "imported proto"dict[Hash] := "stdlib proto"
#> proc$print(dict[proc])#> method$print(dict[method])#> type$print(dict[Task])#> module$print(dict[Left])#> proto$print(dict[Waiting])#> imported proto$print(dict[Left.Ready])#> stdlib proto$print(dict[Behaviors.Hash])#> 7$print(dict.size)
#:left.msmodule Test.Left
proto Ready def ready endend