Something went wrong. Try again.
The Mesa programming language
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257import Core.Behaviors.Equal
$print((1).equal(1))#> true$print("a".equal("b"))#> false$print(nil.equal(nil))#> true$print((1).equal("1"))#> false
#> true$print(1 == 1)#> true$print(1 != 2)#> true$print(nil == nil)#> true$print(true != false)#> true$print('a' == 'a')#> true$print("a" == "a")#> false$print(1 == "1")
#> true$print([1, 2] == [1, 2])#> true$print([[1], [2]] == [[1], [2]])#> true$print([1] != [1, 1])#> true$print({"a": 1, "b": 2} == {"b": 2, "a": 1})#> true$print({"items": [1, 2]} == {"items": [1, 2]})#> true$print([{"a": 1}] == [{"a": 1}])#> false$print({"a": 1} == {"b": 1})
type Task(priority)end
type Group(tasks: []) status := "open"end
type OtherTask(priority)end
#> true$print(Task(5) == Task(5))#> true$print(Task(5) != Task(2))#> true$print(Group([Task(5)]) == Group([Task(5)]))#> trueleft := Group([Task(5)])right := Group([Task(5)])right.status := "done"$print(left != right)#> false$print(Task(5) == OtherTask(5))
type Transaction case Credit(amount) end case Debit(amount) endend
#> false$print(Transaction.Credit(1) == Transaction.Debit(1))#> true$print(Transaction.Credit(1) != Transaction)
type AlwaysEqual(value) def equal(other) "equal" endend
#> true$print(AlwaysEqual(1) == AlwaysEqual(2))#> true$print(AlwaysEqual(1) == Task(1))#> true$print(Group([AlwaysEqual(1)]) == Group([AlwaysEqual(2)]))#> true$print([AlwaysEqual(1)] == [AlwaysEqual(2)])
type NeverEqual(value) impl Equal
def equal(other) false endend
#> false$print(NeverEqual(1) == NeverEqual(1))
type Derived(value) impl Equalend
#> true$print(Derived(1) == Derived(1))
self_list := []self_list << self_listother_self_list := []other_self_list << other_self_list#> true$print(self_list == other_self_list)
two_cycle_a := []two_cycle_b := []two_cycle_a << two_cycle_btwo_cycle_b << two_cycle_a#> true$print(self_list == two_cycle_a)
marked_a := []marked_a << marked_amarked_b := []marked_b << marked_b#> true$print([marked_a, marked_a] != [marked_b, 5])
left_dict := {}left_dict["self"] := left_dictright_dict := {}right_dict["self"] := right_dict#> true$print(left_dict == right_dict)
type Node(next)end
left_node := Node(nil)left_node.next := left_noderight_node := Node(nil)right_node.next := right_node#> true$print(left_node == right_node)
type Link(next) def equal(other) self.next == other.next endend
left_link := Link(nil)left_link.next := left_linkright_link := Link(nil)right_link.next := right_link#> true$print(left_link == right_link)
type Flaky(raising) def equal(other) when self.raising then self.raising := false raise "boom" end false endend
flaky := Flaky(true)other_flaky := Flaky(false)do flaky == other_flakyrescue e case Str then nilend#> false$print(flaky == other_flaky)
#---
type Node(data)end
a := Node(nil)a.data := a
b := Node(nil)c := Node(b)b.data := c
#> true$print(a == b)
#---
import Test.Leftimport Test.Left.Readyimport Test.Right
type Firstend
type Secondend
def firstend
def secondend
proto Waiting def wait endend
#> true$print(Left == Left)#> true$print(Left != Right)#> true$print(First == First)#> true$print(First != Second)#> true$print(&first == &first)#> true$print(&first != &second)#> true$print(Waiting == Waiting)#> true$print(Waiting != Ready)#> true$print(Ready == Left.Ready)
#:left.msmodule Test.Left
proto Ready def ready endend
#:right.msmodule Test.Right
#---
#! runtime error: "boom"
type Explosive(value) def equal(other) raise "boom" endend
Explosive(1) == Explosive(1)